Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Windows Forms
  4. MDI WinForms: Open childform2 in panel2 of Parent form using button of Childform1

MDI WinForms: Open childform2 in panel2 of Parent form using button of Childform1

Scheduled Pinned Locked Moved Windows Forms
csharpwinformsdockerhelp
4 Posts 3 Posters 16 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    Member 10747755
    wrote on last edited by
    #1

    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.

    L 1 Reply Last reply
    0
    • M Member 10747755

      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.

      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #2

      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?

      M 1 Reply Last reply
      0
      • L Lost User

        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?

        M Offline
        M Offline
        MyOwnBoss
        wrote on last edited by
        #3

        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 Sub

        Private 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 = Me

            m\_ChildFormNumber += 1
            ChildForm.Text = "Window " & m\_ChildFormNumber
        
            ChildForm.Show()
        End Sub
        
        L 1 Reply Last reply
        0
        • M MyOwnBoss

          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 Sub

          Private 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 = Me

              m\_ChildFormNumber += 1
              ChildForm.Text = "Window " & m\_ChildFormNumber
          
              ChildForm.Show()
          End Sub
          
          L Offline
          L Offline
          Lost User
          wrote on last edited by
          #4

          Why have you posted this message to me?

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups