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

Opening child from child within parent

P: n/a
Hi Guys,

I have a problem opening a child window within a parent window when passing
a variable between two child windows.

I have the parent window setup with two menuitems. The first calls Form2 and
the second calls Form3

The code follows:-

Private Sub MenuItem1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MenuItem1.Click
Dim NewMDIChild As New Form2
NewMDIChild.MdiParent = Me
NewMDIChild.Show()
End Sub

Private Sub MenuItem2_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MenuItem2.Click
Dim NewMDIChild As New Form3
NewMDIChild.MdiParent = Me
NewMDIChild.Show()
End Sub
On Form2 I have a button which calls Form3 with some text I wish to display
in Form3
Form2 Code follows:-

Private ShowForm3 As New Form3(Me)

Private Sub Form2_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
Label1.Text = "Text to Send"
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
Dim NewMDIChild As New Form3
Dim ShowForm3 = New Form3(Me)
ShowForm3.MdiParent = Me.MdiParent
ShowForm3.Show()
End Sub

The code on Form3 is as follows:-

Private CallingForm As Form2

Public Sub New(ByVal newCallingForm As Form2)
MyBase.New()
InitializeComponent()
CallingForm = newCallingForm
End Sub

Private Sub Form3_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
TextBox1.Text = CallingForm.Label1.Text
End Sub
If I open Form2, click on the button to open Form3 and display the text, all
is OK.
If I only click on "Open Form3" from the mainmenu of Form1 I get an error:-

An unhandled exception of type 'System.OutOfMemoryException' occurred in
system.windows.forms.dll

Additional information: Error creating window handle.

If I edit out the "TextBox1.Text = CallingForm.Label1.Text" statement on
Form2 all is again OK but I can not pass the variable.

Any ideas on how to open Form3 (obviously without the text!)?

Cheers

Peter.

Nov 21 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
Peter,

Assuming from your code that Form3 is a child from Form1 do you need to open
it as a child from form1 and not from form2

For that are in the childs the properties MDIParent and in the parent the
MDIChildren

http://msdn.microsoft.com/library/de...ldrentopic.asp

You need those to do what you want.

You have first to find the index of your form3 in form2

In form2 you work with.

me.mdiparent.mdichildren

I hope this helps,

Cor
Nov 21 '05 #2

P: n/a
Cor,

You are correct in saying that Form3 is a child of Form1. If I do not
reference form3 to form2 (via the TextBox1.Text = CallingForm.Label1.Text
statement) form3 opens from form1 without any problems.

Form2, a child in form1, opens form3 still with form3 as a child in form1. I
am a bit confused about why I need to find the index of form2 when opening
form3 directly from form1.

Thanks

Peter.
"Cor Ligthert" <no************@planet.nl> wrote in message
news:%2****************@TK2MSFTNGP09.phx.gbl...
Peter,

Assuming from your code that Form3 is a child from Form1 do you need to
open it as a child from form1 and not from form2

For that are in the childs the properties MDIParent and in the parent the
MDIChildren

http://msdn.microsoft.com/library/de...ldrentopic.asp

You need those to do what you want.

You have first to find the index of your form3 in form2

In form2 you work with.

me.mdiparent.mdichildren

I hope this helps,

Cor

Nov 21 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.