open child-form

  • Thread starter Filip Vanderstappen
  • Start date
F

Filip Vanderstappen

Hello,

I think a lot of people already asked my question!
I'm learning vb.net and now I have a MDI-parent with one child. Everytime I
press a button to open the child it will open a new form. I want to open a
new child-form when it isn't already open. If the child-form is already
opened I want to put focus to the child-form.

How do I have to solve this problem?

Greets,

Filip
 
H

Herfried K. Wagner [MVP]

Filip Vanderstappen said:
I'm learning vb.net and now I have a MDI-parent with one child. Everytime
I press a button to open the child it will open a new form. I want to open
a new child-form when it isn't already open. If the child-form is already
opened I want to put focus to the child-form.

\\\
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
m_Child.Show()
Else
m_Child.Activate()
End If
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
///
 

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

Top