about OpenFileDialog

  • Thread starter Thread starter violin wang
  • Start date Start date
V

violin wang

hi
I wrote a windows based program.The main UI named
form_base has a button "btn1".In btn1`s click event
handler I used ShowDialog(this) to show another form
named form_test.form_test also has a button btn2 and I
added a openfiledialog in form_test.In btn2 click event
handler I used ShowDialog(this) to show openfiledialog.
When I ran the program, I found that when the
openfiledialog returned, the form_test would close
automatically and returned to form_base.What shall I do
if I want form_test to remain open when openfiledialog
close.

regards
violin
 
Dear violin,

I used the following code:

Form1.cs

private void button1_Click(object sender,
System.EventArgs e)
{

Form2 frm2 = new Form2();
frm2.ShowDialog(this);
}

Form2.cs

private void button1_Click(object sender,
System.EventArgs e)
{
openFileDialog1.ShowDialog(this);
}

I have tried this out, on returning from the
OpenFileDialog, the form2 remains opened. Can you please
check. I think there must be some other reason for this.


Regards,
Puneet Taneja
 
Hi Violin,

Have a look at the form2 properties, to what the accept button is set, it is
maybe the button you use to open the opendialog.

Cor
 
hi
Thanks you for answering my question.
I checked form2 and the btn2 is not the accept
button of form2.Actually I had serval buttons on form2.I
found that the form2 would close if I click any of these
buttons even I didn`t wrote click event handler for it.It
was so strange, so I deleted form2 and recreated it.This
time, form2 is remain open if i click any button on it.I
don`t know reason.Is there someone know it?


regards
violin
 
Back
Top