Quantcast
Channel: Programming Forums
Viewing all articles
Browse latest Browse all 51036

Get the path from FolderBrowseDialog from another form.

$
0
0
Hi. How can I get the path selected by the FolderBrowseDialog from Form1 into Form2?

Form1.cs
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
        public string path;

        private void button2_Click(object sender, EventArgs e)
        {
            FolderBrowserDialog fbd = new FolderBrowserDialog();
            if (fbd.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                path = fbd.SelectedPath;
            }
        }


        private void button1_Click(object sender, EventArgs e)
        {
            Form2 form2 = new Form2();
            form2.Show();
        }
    }


Form2.cs
    public partial class Form2 : Form
    {
        public Form2()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            Form1 form1 = new Form1();
            MessageBox.Show(form1.path);
        }
    }



I tried this but it only return path as null.

Viewing all articles
Browse latest Browse all 51036

Trending Articles