last day (15 days later) » 

11:57
0
Q: How to open "openFileDialog" by button click?

userdavidI would like to open the openFileDialog at the click of a button. But all my efforts are unsuccessful. I tried this: private void button1_Click(object sender, EventArgs e) { var dialog = new OpenFileDialog(); if (dialog.ShowDialog() == DialogResult.OK) ...

TaW
TaW
What are you targetting: Winforms, WPF, ASP..? YOU should always TAG your questions correctly so one can see it on the questions page! - the window disappears right away Really??? You should set up the dialog befor you show it but it should show just fine. Of course the stuff you later do will not show.. - And you need to use the dialog, not some openFileDialog1 !!
@Steve DialogResult is set to None
@TaW Is it better?
TaW
TaW
Looks even better. But still the dialog ought to show up in any case. Do us all a favor and use your best friend, the debugger!
@Steve Side note is added, the window that pops up is very fast so I don't even know if it's an openfiledialog
@TaW with debugger I´m not good freind :( in my language isnÅ¥ good instructions unfortunately
TaW
TaW
Then now is the time to learn it! Really !! Just add a breakpoint at the line with the showdialog and step once.. To set a breakpoint click at the grey part to the left of the line number. It will creat a dark red circle.. - To step press F11 !
11:57
@TaW okey I try it, thank you!
@TaW when i click on f11 it throws me into program.cs, is it ok?
TaW
TaW
You did set the beakpoint? and then started the program? If not press F5 ! Now your button should come up and when you click it the debugger should stop at the breakpoint..
@TaW Yes my button showed up when I clicked on it nothing happened, I guess it's supposed to show where the debbuger read the code
TaW
TaW
In which line exactly is the breakpoint?
in line if (dialog.ShowDialog() == DialogResult.OK)
TaW
TaW
Also: Is the click event even hooked up (i.e. registered)?? Look in the button's properties-event pane and check that the Click event has the button1_Click !
12:00
until now
it already works thanks a lot !!!!!!
TaW
TaW
ok. bye..

last day (15 days later) »