Really basic forms question (just learning!)

  • Thread starter Thread starter Rich
  • Start date Start date
R

Rich

Hi,

I have the following code to open a Windows form:

Dim oFrm As New frmEquipmentAdd()
oFrm.Show()
oFrm = Nothing

I don't want the user to be able to open the form multiple times. Can
anyone tell me what I can add to this code to check if the form is already
open, and if it is, not to open it a second time?

Thanks
Richard
 
* "Rich said:
I have the following code to open a Windows form:

Dim oFrm As New frmEquipmentAdd()
oFrm.Show()
oFrm = Nothing

Setting 'oFrm' to 'Nothing' doesn't make much sense here.
I don't want the user to be able to open the form multiple times. Can
anyone tell me what I can add to this code to check if the form is already
open, and if it is, not to open it a second time?

\\\
Private myform As Form2

Private Sub Button1_Click( _
ByVal sender As System.Object, _
ByVal e As System.EventArgs _
) Handles Button1.Click
If myform Is Nothing Then
myform = New Form2()
'myform.MdiParent = Me
AddHandler myform.Closed, AddressOf Me.ChildForm_Closed
myform.Show()
Else
'MsgBox("Form already open: " & myform.Text)
Me.ActivateMdiChild(myform)
End If
End Sub

Private Sub ChildForm_Closed( _
ByVal sender As Object, _
ByVal e As System.EventArgs _
) Handles MyBase.Closed
myform = Nothing
End Sub
///

Alternatively, you can implement the singleton design pattern (see
Google Groups Search on this group for links).
 
That worked really well, apart from one small problem. I am opening the
child form from a mainmenu on the original form. The first time I open the
child form it works fine, but the second time I try to open the child form
when it is already open my menu on my original for disappears?

Any ideas?

Many thanks
Richard
 
Back
Top