By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,212 Members | 1,076 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,212 IT Pros & Developers. It's quick & easy.

Is my Form Loaded??

P: n/a
In MDI interface, suppose i have a form named "FORM" , how do i check if its
already loaded or not ??
Nov 21 '05 #1
Share this Question
Share on Google+
4 Replies


P: n/a
"Arsalan" <ar***********@hotmail.com> schrieb:
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.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>

Nov 21 '05 #2

P: n/a
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

"Herfried K. Wagner [MVP]" <hi***************@gmx.at> wrote in message
news:eB**************@TK2MSFTNGP14.phx.gbl...
"Arsalan" <ar***********@hotmail.com> schrieb:
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.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>

Nov 21 '05 #3

P: n/a
Thanks
"Herfried K. Wagner [MVP]" <hi***************@gmx.at> wrote in message
news:eB**************@TK2MSFTNGP14.phx.gbl...
"Arsalan" <ar***********@hotmail.com> schrieb:
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.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>

Nov 21 '05 #4

P: n/a
Lloyd

And therfore is the

me.MDIchildren where they are all in.

They are easy to find using that.

Cor

"Lloyd Sheen" <sq*******************@tostopspamhotmail.com>

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

"Herfried K. Wagner [MVP]" <hi***************@gmx.at> wrote in message
news:eB**************@TK2MSFTNGP14.phx.gbl...
"Arsalan" <ar***********@hotmail.com> schrieb:
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.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>


Nov 21 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.