Home > Back-end >  opening folder browser dialog on button click c#
opening folder browser dialog on button click c#

Time:01-05

im trying to trigger a folder browser dialog with a button in c# ive tried

     private void Button2_Click(object sender, EventArgs e)
 {
     DialogResult auswahl2 = folderBrowserDialog2.ShowDialog();
     if (auswahl2 == DialogResult.OK)
     {
         TextBox5.Text = folderBrowserDialog2.SelectedPath;
     }
 }

but neither debug nor release will open one on button click. What am i missing ?

Thanks in Advance

CodePudding user response:

Your code works perfectly but check if Button2_Click(object sender, EventArgs e) event is plugged.

Mehdi

CodePudding user response:

Go to your form, and double-click the button in question, see if it pointed to the above function, or a new event function is created.

If it was the second, copy everything above to the new function and run the program again, everything should be fine after that.

If you want to do it manually, go to YourForm.Designer.cs, and add this.Button2.Click = new System.EventHandler(this.Button2_Click); under InitializeComponent().

Or go to the code of your form, select InitializeComponent under the constructor, and press F12, and it will bring you to the right place.

  •  Tags:  
  • Related