MDI WinForms: Open childform2 in panel2 of Parent form using button of Childform1
-
I'm developing a MDI WinForm App using C#. I have a parent window with a splitContainer. Panel2 of the split container is used to used to display child forms while Panel1 is used for controls of the parent window. Child1 loads with parent form . However I have placed a button in Child1 that has to call child2 but I can't seem to find a way to close child1 and show child2 in panel2 of the Parent Split Container. I tried using the User Controls but I can't seem to pull through.. Please help.
-
I'm developing a MDI WinForm App using C#. I have a parent window with a splitContainer. Panel2 of the split container is used to used to display child forms while Panel1 is used for controls of the parent window. Child1 loads with parent form . However I have placed a button in Child1 that has to call child2 but I can't seem to find a way to close child1 and show child2 in panel2 of the Parent Split Container. I tried using the User Controls but I can't seem to pull through.. Please help.
-
I'm not sure I understand completely, but how about using that button to call a method in the parent that will close Child1 and replace it with Child2?
Here are a few methods I use. Adapt as needed.
'Determines if a form is already open.
Public Function IsFormOpen(ByVal FormName As String) As Boolean
Dim rVal As Boolean = False
Dim frm As Form
For Each frm In Me.MdiChildren
If frm.Name = FormName Then
rVal = True
Exit For
End If
Next
Return rVal
End Function'Function to show a MDI child form.
Public Function ShowMdiChild(ByVal FormName As String) As Boolean
Dim rVal As Boolean = False
Dim frm As Form
For Each frm In Me.MdiChildren
If frm.Name = FormName Then
rVal = True
frm.Activate()
frm.WindowState = FormWindowState.Maximized
Exit For
End If
Next
Return rVal
End Function'Invoke a public sub in a MDI child form.
Public Sub InvokeMdiChildMethod(ByVal MethodName As String)
Dim o As Object
o = Me.ActiveMdiChild
Try
o.GetType().GetMethod(MethodName).Invoke(o, Nothing)
Catch
End Try
End SubPrivate Sub ShowNewForm(ByVal sender As Object, ByVal e As EventArgs) Handles NewToolStripMenuItem.Click, NewToolStripButton.Click, NewWindowToolStripMenuItem.Click
' Create a new instance of the child form.
Dim ChildForm As New System.Windows.Forms.Form
' Make it a child of this MDI form before showing it.
ChildForm.MdiParent = Mem\_ChildFormNumber += 1 ChildForm.Text = "Window " & m\_ChildFormNumber ChildForm.Show() End Sub
-
Here are a few methods I use. Adapt as needed.
'Determines if a form is already open.
Public Function IsFormOpen(ByVal FormName As String) As Boolean
Dim rVal As Boolean = False
Dim frm As Form
For Each frm In Me.MdiChildren
If frm.Name = FormName Then
rVal = True
Exit For
End If
Next
Return rVal
End Function'Function to show a MDI child form.
Public Function ShowMdiChild(ByVal FormName As String) As Boolean
Dim rVal As Boolean = False
Dim frm As Form
For Each frm In Me.MdiChildren
If frm.Name = FormName Then
rVal = True
frm.Activate()
frm.WindowState = FormWindowState.Maximized
Exit For
End If
Next
Return rVal
End Function'Invoke a public sub in a MDI child form.
Public Sub InvokeMdiChildMethod(ByVal MethodName As String)
Dim o As Object
o = Me.ActiveMdiChild
Try
o.GetType().GetMethod(MethodName).Invoke(o, Nothing)
Catch
End Try
End SubPrivate Sub ShowNewForm(ByVal sender As Object, ByVal e As EventArgs) Handles NewToolStripMenuItem.Click, NewToolStripButton.Click, NewWindowToolStripMenuItem.Click
' Create a new instance of the child form.
Dim ChildForm As New System.Windows.Forms.Form
' Make it a child of this MDI form before showing it.
ChildForm.MdiParent = Mem\_ChildFormNumber += 1 ChildForm.Text = "Window " & m\_ChildFormNumber ChildForm.Show() End Sub