Close the opened form

  • Thread starter Thread starter anthony
  • Start date Start date
A

anthony

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
 
anthony said:
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
///
 
Back
Top