Use a variable declared in one form, in another form c#
<p>I have this little project here, where i have declared a variable named "dir" with a directory selected in a Folder Browser dialog in my form called main.cs:</p>

<pre><code>namespace XmoSupportTools
{
public partial class Main : Form
{
    public string dir;

    public FolderBrowserDialog xmodialog { get; private set; }
    public DialogResult xmodialogresult { get; private set; }

    //metoder der bliver brugt senere
    public void startxmo()
    {
        string startfile = dir + "\\xmo.exe";
        Process xmoappli = new Process();

        if (File.Exists(startfile))
        {
            xmoappli.StartInfo.FileName = startfile;
            xmoappli.Start();
        }
        else
        {
            MessageBox.Show("XMO.exe blev ikke fundet på den valgte lokation!");
            File.Delete(dir + "\\xmo.ini");
            dialog();
        }

    }

    public void dialog()
    {

        xmodialog = new FolderBrowserDialog();
        xmodialog.Description = "Find dit XMO Directory:";
        xmodialogresult = xmodialog.ShowDialog();
        if (xmodialogresult == DialogResult.OK)
        {
            dir = xmodialog.SelectedPath;

        }
</code></pre>

<p>I want to use that "dir" variable in my second form called Kunde.cs:</p>

<pre><code>public void startxmo()
    {
        string startfile = dir + "\\xmo.exe";
        Process xmoappli = new Process();

        if (File.Exists(startfile))
        {
            xmoappli.StartInfo.FileName = startfile;
            xmoappli.Start();
        }
        else
        {
            MessageBox.Show("XMO.exe blev ikke fundet på den valgte lokation!");
            File.Delete(dir + "\\xmo.ini");
            dialog();
        }

    }
</code></pre>