Opening forms in a tab

I have an mdi form with a few smaller forms that open within it. I recently decided that I do not want to do this. Is there a way to open the forms I have already created in a tab

Say I have Form2.vb as a child form of Form1.vb. Right now, I have it set as I click a button and Form2 opens in a child window. Instead, I want to create a new tab on my tabcontrol and open it there (no new child window). I don't want to write out all the code that creates the controls by hand as the designer already did that for me. How would I take the code in Form2.Designer.vb and make it apply to a newly created tab

If this doesn't make sense then I apologize. Let me know whih part doesn't make sense and I shall specify further. Thanks.




Answer this question

Opening forms in a tab

  • Balaji Thiruvenkataraju

    I am still trying to figure this out. I want a form to open in a new tab in a tabcontrol instead of opening in a window. Thanks.


  • Colin Hardie

    The following code should do, altough I must say that looks like a hack, let's hope WinForms won't get mad when it will see this (I've tried it and works, but how knows...)

    I have a form, Form1, with a tab control with a page in it, TabPage1, and a button, Button1 with the following Click handler. Form2 is the form you want to put inside the TabPage.

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click


    Dim form2 As New Form2


    form2.TopLevel = False
    form2.FormBorderStyle = Windows.Forms.FormBorderStyle.None
    form2.Dock = DockStyle.Fill
    form2.Visible = True


    TabPage1.Controls.Add(form2)
    End Sub


  • nigelborrill

    That worked beautifully. I would have been stuck on the toplevel thing forever.

    Another question about my tabs. Is there a way to make it to where if you have already opened a form in a tab and you try to again instead of opening a new tab it focuses to already open tab That may be confusing. Thanks.



  • Opening forms in a tab