Is my Form Loaded??

  • Thread starter Thread starter Arsalan
  • Start date Start date
A

Arsalan

In MDI interface, suppose i have a form named "FORM" , how do i check if its
already loaded or not ??
 
Arsalan said:
In MDI interface, suppose i have a form named "FORM" , how do i check if
its already loaded or not ??

\\\
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.
 
Not to say that this will not work but the whole idea behind MDI is
surprisingly MULTIPLE documents shown in a single workplace. The code
presented will handle the opening of one document and its close. To make
this work for all situations you need to have the MDI children as an array.

There is this one extra level of complexity that requires each document to
have some property that can be queried to determine not if the form is
loaded but if the form is loaded due to the presentation of a certain
document or piece of information.

To change the code presented you simply need to add the reference to an
array when loaded and then removed from the array when closed. Then to see
if the form for a particular item is loaded it becomes a case of looping
thru the array, checking the type of the form and for each form of a
particular type checking the property to determine the document being
presented by the form.

Lloyd Sheen
 
Thanks
Herfried K. Wagner said:
\\\
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.
 
Lloyd

And therfore is the

me.MDIchildren where they are all in.

They are easy to find using that.

Cor

Not to say that this will not work but the whole idea behind MDI is
surprisingly MULTIPLE documents shown in a single workplace. The code
presented will handle the opening of one document and its close. To make
this work for all situations you need to have the MDI children as an
array.

There is this one extra level of complexity that requires each document to
have some property that can be queried to determine not if the form is
loaded but if the form is loaded due to the presentation of a certain
document or piece of information.

To change the code presented you simply need to add the reference to an
array when loaded and then removed from the array when closed. Then to
see if the form for a particular item is loaded it becomes a case of
looping thru the array, checking the type of the form and for each form of
a particular type checking the property to determine the document being
presented by the form.

Lloyd Sheen
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top