none
How to convert a child form to a parent form in vb.net ? RRS feed

  • Question

  • Already I declare  parent and child form, Now I want to convert a child form as a parent form, Is it possible in vb.net 2008? If yes, please provide code .
    Wednesday, May 8, 2013 3:48 AM

Answers

  • A MDI Child form is no different than any other form - it's all in the way it is created.   This is the code used to create an instance of a form as an MDI child.  It would usually be in one of the click events of the MDI ToolStrip menu.

            ' Create a new instance of the child form.
            Dim myChildForm As New ChildForm
            ' Make it a child of this MDI form before showing it.
            myChildForm.MdiParent = Me
    
            m_ChildFormNumber += 1
            myChildForm.Text = "Window " & m_ChildFormNumber
    
            myChildForm.Show()

    You can use nearly the same code, but put it in the event handler for whatever event should show the form.  For instance, it might be in a button click event.  Since you are not interested in establishing a parent/child relationship, leave out that part of the code:

            ' Create a new instance of the form.
            Dim myChildForm As New ChildForm
            myChildForm.Show()

    Wednesday, May 8, 2013 5:13 AM
  • If you want an existing form to be a MDI container form, that is a different question, and I would recommend that it is easier to start over with a new MDI container form.

    Otherwise, you could create a new MDI container form to see how it is different than a standard form.  Then add those changes into your existing form one by one.

    Wednesday, May 8, 2013 11:40 AM

All replies

  • What exactly do you mean by 'child' and 'parent'?   Are you talking about MDI forms, or are you talking about the logical relationship between forms within a particular application?

    Generally, whether a form is regarded as a 'child' or 'parent' is controlled by how the form is actually used in your code - there is no 'conversion' of the form involved.

    Wednesday, May 8, 2013 3:54 AM
  • MDIContainer

    Wednesday, May 8, 2013 4:00 AM
  • A MDI Child form is no different than any other form - it's all in the way it is created.   This is the code used to create an instance of a form as an MDI child.  It would usually be in one of the click events of the MDI ToolStrip menu.

            ' Create a new instance of the child form.
            Dim myChildForm As New ChildForm
            ' Make it a child of this MDI form before showing it.
            myChildForm.MdiParent = Me
    
            m_ChildFormNumber += 1
            myChildForm.Text = "Window " & m_ChildFormNumber
    
            myChildForm.Show()

    You can use nearly the same code, but put it in the event handler for whatever event should show the form.  For instance, it might be in a button click event.  Since you are not interested in establishing a parent/child relationship, leave out that part of the code:

            ' Create a new instance of the form.
            Dim myChildForm As New ChildForm
            myChildForm.Show()

    Wednesday, May 8, 2013 5:13 AM
  • Mr.Acamar, Thanks for your reply, Actually I had a doubt is it possible to convert a child form as  anew parent form. (ie, mychildform is possible to convert as a parent form )

    Wednesday, May 8, 2013 11:29 AM
  • If you want an existing form to be a MDI container form, that is a different question, and I would recommend that it is easier to start over with a new MDI container form.

    Otherwise, you could create a new MDI container form to see how it is different than a standard form.  Then add those changes into your existing form one by one.

    Wednesday, May 8, 2013 11:40 AM