Opening MDI childforms


B

Bob

Hi everyone:

I am relatively new to VB.NET, but have used VB 6.0 for several years. I
have an MDI application with 3 forms. Form1 is the parent, and Form2 and
Form3 are the child. Can someone tell me how to open Form2 from Form1 and
Form3 from Form2 by clicking on command buttons?

Here is my code for Form1:

Dim childForm As Integer = 0
Dim childForms() As Form2

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
childForm += 1
ReDim Preserve childForms(childForm)
childForms(childForm) = New Form2
childForms(childForm).Text = "ChildForm" & Str(childForm)
'setting title for child windows and incrementing the number with an
array
childForms(childForm).MdiParent = Me
childForms(childForm).Show()
End Sub


Here is the code for Form2:

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
Dim DumbForm3 As Form3
Dim DumbMDI As Form1

DumbForm3 = New Form3
DumbForm3.Text = "ChildForm DumbForm3"
DumbForm3.MdiParent = DumbMDI
DumbForm3.Show()

End Sub

When I run this, Form3 is not a child form. Thanks for your help.

Bob
 
Ad

Advertisements

A

Armin Zingler

Bob said:
Hi everyone:

I am relatively new to VB.NET, but have used VB 6.0 for several
years. I have an MDI application with 3 forms. Form1 is the
parent, and Form2 and Form3 are the child. Can someone tell me how
to open Form2 from Form1 and Form3 from Form2 by clicking on command
buttons?

Here is my code for Form1:

Dim childForm As Integer = 0
Dim childForms() As Form2

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e
As System.EventArgs) Handles Button1.Click


Side note: You may use an arraylist instead of the array, or, in VB 2005, a
List(Of)

childForm += 1
ReDim Preserve childForms(childForm)
childForms(childForm) = New Form2
childForms(childForm).Text = "ChildForm" & Str(childForm)
'setting title for child windows and incrementing the number
with an array
childForms(childForm).MdiParent = Me
childForms(childForm).Show()
End Sub


Here is the code for Form2:

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e
As System.EventArgs) Handles Button1.Click
Dim DumbForm3 As Form3
Dim DumbMDI As Form1

DumbForm3 = New Form3
DumbForm3.Text = "ChildForm DumbForm3"
DumbForm3.MdiParent = DumbMDI
DumbForm3.Show()

End Sub

When I run this, Form3 is not a child form. Thanks for your help.

You declared DumbMDI but it contains Nothing.


Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
Dim DumbForm3 As Form3

DumbForm3 = New Form3
DumbForm3.Text = "ChildForm DumbForm3"
DumbForm3.MdiParent = Me.MdiParent
DumbForm3.Show()

End Sub



Armin
 
B

Bob

Hi Armin:

Thanks for your reply. I just have a question. Why do you use DumbForm3 =
New Form3? Form3 is not a new instance. It already exists. Your help is
appreciated.

Bob
 
A

Armin Zingler

Bob said:
Hi Armin:

Thanks for your reply. I just have a question. Why do you use
DumbForm3 = New Form3? Form3 is not a new instance. It already
exists. Your help is appreciated.

I don't understand. That's /your/ code. /You/ wrote "DumbForm3 = New Form3".
The only thing I changed was
DumbForm3.MdiParent = DumbMDI
to
DumbForm3.MdiParent = Me.MdiParent

(and I removed variable DumbMDI because it's not used anymore)

Armin
 
Ad

Advertisements

B

Bob

Thanks Armin. I got confused. I am still trying to adjust to the VB.Net
environment. It is really different than vb 6.0. Thanks.

Bob
 

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