[Color=Green]' Option 1 - Only works if there is only one Form2, not very MDI friendly.
[/Color] [Color=Blue] Private Sub [/Color]NewDocumentToolStripMenuItem_Click([Color=Blue]ByVal [/Color]sender [Color=Blue]As [/Color]System.Object, [Color=Blue]ByVal [/Color]e [Color=Blue]As [/Color]System.EventArgs) [Color=Blue]Handles [/Color]NewDocumentToolStripMenuItem.Click
Form2.Text = "New Document " + ([Color=Blue]Me[/color].MdiChildren.Length + 1).ToString()
Form2.MdiParent = [Color=Blue]Me[/Color]
Form2.WindowState = FormWindowState.Maximized
Form2.Show()
Form2.Update()
[Color=Blue]End Sub[/Color]
[Color=Blue]Private Sub [/Color]ShowTextInTheSelectedChildFormToolStripMenuItem_Click([Color=Blue]ByVal [/Color]sender [Color=Blue]As [/Color]System.Object, [Color=Blue]ByVal [/Color]e [Color=Blue]As [/Color]System.EventArgs) [Color=Blue]Handles [/Color]ShowTextInTheSelectedChildFormToolStripMenuItem.Click
MessageBox.Show(Form2.TextBox1.Text)
[Color=Blue] End Sub[/Color]
[Color=Green]' Option 2 - Probably better[/Color]
[Color=Blue]Dim [/Color]Documents [Color=Blue]As New [/Color]List([Color=Blue]Of [/Color]Form2) [Color=Green]' Depending on your approach, you might not need this.[/Color]
[Color=Blue] Private Sub [/Color]NewDocumentToolStripMenuItem_Click([Color=Blue]ByVal [/Color]sender [Color=Blue]As [/Color]System.Object, [Color=Blue]ByVal [/Color]e [Color=Blue]As [/Color]System.EventArgs) [Color=Blue]Handles [/Color]NewDocumentToolStripMenuItem.Click
[Color=Blue]Dim [/Color]Document [Color=Blue]As [/Color]Form2 = [Color=Blue]New [/Color]Form2
Document.Text = "New Document " + ([Color=Blue]Me[/color].MdiChildren.Length + 1).ToString()
Document.MdiParent = [Color=Blue]Me[/Color]
Document.WindowState = FormWindowState.Maximized
Document.Show()
Form2.Update()
Documents.Add(Document)
[Color=Blue] End Sub[/Color]
[Color=Blue]Private Sub [/Color]ShowTextInTheSelectedChildFormToolStripMenuItem_Click([Color=Blue]ByVal [/Color]sender [Color=Blue]As [/Color]System.Object, [Color=Blue]ByVal [/Color]e [Color=Blue]As [/Color]System.EventArgs) [Color=Blue]Handles [/Color]ShowTextInTheSelectedChildFormToolStripMenuItem.Click
[Color=Green] ' I don't know how you plan on picking wich document to perform the action
' This would perform the action on all documents
[/Color] [Color=Blue]For Each [/Color]Document [Color=Blue]As [/Color]Form2 [Color=Blue]In [/Color]Documents
MessageBox.Show(Document.TextBox1.Text)
[Color=Blue]Next[/Color]
[Color=Green]' This would perform the action on the currently active document
[/Color] [Color=Blue]Dim [/Color]SingleDocument [Color=Blue]As [/Color]Form2 = [Color=Blue]TryCast[/Color](Me.ActiveMdiChild, Form2)
[Color=Blue]If [/Color](Form2 [Color=Blue]IsNot Nothing[/Color]) [Color=Blue]Then[/Color]
MessageBox.Show(SingleDocument.TextBox1.Text)
[Color=Blue]End If
End Sub[/Color]