limiting to only one child form per type of form

  • Thread starter Thread starter federico
  • Start date Start date
F

federico

Hello, every time I click on the button to open the child form, the form
opens fine, but if I click the button again, the same form opens again. I
would like to limit to one instance each particular form. I thought a would
add a condition to the code for the new form bottom click event (below), but
I don't know how to check to see if the form is already open. Could anyone
please help?

federico

Private Sub tbrMain_ButtonClick(ByVal sender As System.Object, ByVal e As _
System.Windows.Forms.ToolBarButtonClickEventArgs) Handles
tbrMain.ButtonClick
Dim NewMDIChild As New frmHardware
'Set the Parent Form of the Child window.
NewMDIChild.MdiParent = Me
'Display the new form.
NewMDIChild.Show()
End Sub
 
federico said:
Hello, every time I click on the button to open the child form, the
form opens fine, but if I click the button again, the same form opens
again. I would like to limit to one instance each particular form.
I thought a would add a condition to the code for the new form bottom
click event (below), but I don't know how to check to see if the form
is already open. Could anyone please help?

federico

Private Sub tbrMain_ButtonClick(ByVal sender As System.Object, ByVal
e As _ System.Windows.Forms.ToolBarButtonClickEventArgs) Handles
tbrMain.ButtonClick
Dim NewMDIChild As New frmHardware
'Set the Parent Form of the Child window.
NewMDIChild.MdiParent = Me
'Display the new form.
NewMDIChild.Show()
End Sub


Private m_Child As frmHardware

Private Sub OpenChild()
If m_Child Is Nothing Then
m_Child = New frmHardware
AddHandler m_Child.Closed, AddressOf OnChildClosed
m_Child.MdiParent = Me
m_Child.Show()
End If
m_Child.Activate()
End Sub

Private Sub OnChildClosed( _
ByVal sender As Object, ByVal e As System.EventArgs)

RemoveHandler m_Child.Closed, AddressOf OnChildClosed
m_Child = Nothing
End Sub
 
This works great! Thank you.

federico

Armin Zingler said:
Private m_Child As frmHardware

Private Sub OpenChild()
If m_Child Is Nothing Then
m_Child = New frmHardware
AddHandler m_Child.Closed, AddressOf OnChildClosed
m_Child.MdiParent = Me
m_Child.Show()
End If
m_Child.Activate()
End Sub

Private Sub OnChildClosed( _
ByVal sender As Object, ByVal e As System.EventArgs)

RemoveHandler m_Child.Closed, AddressOf OnChildClosed
m_Child = Nothing
End Sub


--
Armin

http://www.plig.net/nnq/nquote.html
http://www.netmeister.org/news/learn2quote.html
 
* "federico said:
Hello, every time I click on the button to open the child form, the form
opens fine, but if I click the button again, the same form opens again. I
would like to limit to one instance each particular form. I thought a would
add a condition to the code for the new form bottom click event (below), but
I don't know how to check to see if the form is already open.

<http://www.google.com/[email protected]>
 
Back
Top