Windows Form hiding after Open File Dialog Ok or Cancel

EDN Admin

Well-known member
Joined
Aug 7, 2010
Messages
12,794
Location
In the Machine
Hi all,
As part of a new program, I need 2 forms and an openfiledialog. On Form1, a button event opens Form2. Form2 has an openfiledialog triggered by a button shown below.

<div style="color:black; background-color:white
<pre> <span style="color:green Form1s button to open Form2
<span style="color:blue Private <span style="color:blue Sub Button1_Click(sender <span style="color:blue As System.Object, e <span style="color:blue As System.EventArgs) <span style="color:blue Handles Button1.Click
Form2.ShowDialog()
<span style="color:blue End <span style="color:blue Sub

<span style="color:green -------------------------

<span style="color:green Form2s Browse button to open the OpenFileDialog and check for result.
<span style="color:blue Private <span style="color:blue Sub browseButton_Click(sender <span style="color:blue As System.Object, e <span style="color:blue As System.EventArgs) <span style="color:blue Handles browseButton.Click
<span style="color:blue If OpenFileDialog1.ShowDialog() = DialogResult.OK <span style="color:blue Then
TextBox1.Text = OpenFileDialog1.FileName
<span style="color:blue End <span style="color:blue If
<span style="color:blue End <span style="color:blue Sub
[/code]


<br/>
However, it seems that because I use ShowDialog() when opening Form2, it hides after the openFileDialog is OK or cancel.
Is there anyway I can keep form2 shown after the openfiledialog is closed? I have tried Me.Show(), Me.BringToFront, and Me.Focus() in the browseButton.Click Event but cannot seem to focus the dialog.
This error does not occur when I change Form1s Button1.Click Event to Form2.<span style="text-decoration:underline Show(). So why does this "error" occur when I use showDialog?
Thanks,
- Jordan
<
<span style="color:green If you find an answer helpful, click the Helpful button. If you find an answer to your question, mark it as the answer.<br/>
metasdevelopment.com www.metasdevelopment.com
Helpful Links:<br/>



<span style="font-style:normal http://msdn.microsoft.com/en-us/library/aa188202(office.10).aspx Visual Basic for Applications (VBA) Information
<span style="font-style:normal http://social.msdn.microsoft.com/Forums/en-US/isvvba/threads Visual Basic for Applications (VBA) MSDN Forum
<span style="font-style:normal http://www.developerfusion.com/tools/convert/csharp-to-vb/ Convert C# to VB.Net

<br/>
http://www.metasdevelopment.com" target="_blank <img src="http://metasdevelopment.files.wordpress.com/2011/08/mcc11_logo_horizontal_full-color.jpg" alt="
<br/>

View the full article
 
Back
Top