oscar said:
i have a Form1 that is opening Form2 by calling Form2.Show()
is there an easy way to check for a child? for Form1 to see if there is
already a Form2 on this thread. there can be 2 Form1s, so it needs to
look
for the Form2 that it oppened.
\\\
Private m_Child As Form2
Private Sub Button1_Click( _
ByVal sender As Object, _
ByVal e As EventArgs _
) Handles Button1.Click
If m_Child Is Nothing Then
m_Child = New Form2()
m_Child .MdiParent = Me
AddHandler m_Child.Load, AddressOf Me.MdiChild_Load
AddHandler m_Child.Closed, AddressOf Me.MdiChild_Closed
End If
m_Child.Show() ' ...
End Sub
Private Sub MdiChild_Load( _
ByVal sender As Object, _
ByVal e As EventArgs _
)
MsgBox( _
"MDI child with handle " & _
DirectCast(sender, Form).Handle.ToString() & _
" loaded!" _
)
End Sub
Private Sub MdiChild_Closed( _
ByVal sender As Object, _
ByVal e As EventArgs _
)
MsgBox( _
"MDI child with handle " & _
DirectCast(sender, Form).Handle.ToString() & _
" closed!" _
)
m_Child = Nothing
End Sub
///
Alternatively you can implement the Singleton design pattern in your MDI
child form:
Implementing the Singleton Pattern in C#
<URL:
http://www.yoda.arachsys.com/csharp/singleton.html>
Exploring the Singleton Design Pattern
<URL:
http://msdn.microsoft.com/library/en-us/dnbda/html/singletondespatt.asp>
Design Pattern: Singleton in C#
<URL:
http://www.devhood.com/tutorials/tutorial_details.aspx?tutorial_id=486>
Design Patterns: Singleton
<URL:
http://www.dofactory.com/Patterns/PatternSingleton.aspx>