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.