Determine if form is open?

  • Thread starter Thread starter able
  • Start date Start date
A

able

Dear friends

Somebody an idea on this matter?

I have two forms in my app, form1 and form2

In form1 there is two buttons:
Private myForm2 AS New Form2
Private Sub Button1_Click...
myForm2.Show()
End Sub

Private Sub Button2_Click...
"Here I want to determine if Form2 is already open or not"
End Sub

Regards Able
 
You could have x,000,000 instances of Form2 open at any time so I'm not sure
what that will do for you. If this is a MDI Scenario then you can loop
through the MDI Children and look for it though. Remember that Form2 is a
class not an instance.
 
Able,

I don't like this sample I just made, however it seems to work.

Try it and I hope it helps?

Cor

\\\
Private WithEvents frm2 As Form2
Private Sub Button1_Click1(ByVal sender As Object, _
ByVal e As System.EventArgs) Handles Button1.Click
If frm2 Is Nothing Then
frm2 = New Form2
frm2.Show()
End If
End Sub
Private Sub Button2_Click1(ByVal sender As Object, _
ByVal e As System.EventArgs) Handles Button2.Click
If Not frm2 Is Nothing Then
MessageBox.Show("Hello I am open")
Else
MessageBox.Show("Hello I am closed")
End If
End Sub
Private Sub frm2_IsClosed() Handles frm2.IsClosed
frm2 = Nothing
End Sub
///
\\\
Friend Event IsClosed()
Private Sub Form2_Closed(ByVal sender As Object, _
ByVal e As System.EventArgs) Handles MyBase.Closed
RaiseEvent IsClosed()
End Sub
///
 
Back
Top