469,625 Members | 1,094 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,625 developers. It's quick & easy.

Close the opened form

Hi,

I have a button (Button1) to open the main form. If I want to have another
button to close this opened form, how do I do it without making Mainform a
global variable?

Thanks!

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click

Dim MainFrom As New frmMain

MainFrom.Show()

End Sub

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button2.Click

' Close the form opened by Button1

End Sub
Nov 21 '05 #1
1 1043
"anthony" <an*******@controlengineer.com> schrieb:
I have a button (Button1) to open the main form. If I want to have
another
button to close this opened form, how do I do it without making Mainform a
global variable?


\\\
Private m_MainForm As MainForm
..
..
..

' In the open button's 'Click' event handler...
If m_MainForm IsNothing OrElse m_MainForm.IsDisposed Then
m_MainForm = New MainForm()
m_MainForm.Show()
End If
..
..
..

' In the close button's 'Click' event handler...
If Not m_MainForm Is Nothing AndAlso Not m_MainForm.IsDisposed Then
m_MainForm.Close()
End If
///

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>

Nov 21 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by Obscurr | last post: by
2 posts views Thread by Bruno Rodrigues | last post: by
3 posts views Thread by Todd Jaspers | last post: by
2 posts views Thread by jpr | last post: by
6 posts views Thread by =?Utf-8?B?UGF1bA==?= | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.