nightfire001
nightfire001

Reputation: 779

How to open new form as new tab in tab control?

I have three forms named, MainForm, Form1 and Form2. In MainForm there is one TabControl. I want to open the forms: Form1 and Form2 as new tab in MainForm. I am using Visual Studio and language VB.Net. Is there any way to open the forms as new tab?

Upvotes: 0

Views: 4557

Answers (1)

Rudi
Rudi

Reputation: 3228

You could change Form1 and Form2 both to be UserControls, you can then load those usercontrols a the contents of the tabs.

To change the Form to a UserControl change the following line:

public partial class Form1 : Form

to

public partial class Form1 : UserControl

Best practice is to also rename the Form1 by renaming the file in the Solution Explorer. VS should show you a popup window:


Microsoft Visual Studio

You are renaming a file. Would you also like to perform a rename in this project of all references to the code element 'Form1'?

Yes No

Click Yes

Then Build your solution, and open your main form with the TabControl in it. Also open the ToolBox window, you should see your new UserControl listed on the top. You can now drag 'n drop your usercontrol onto the TabPage that you want.

Question: do you need to show Form1 and Form2 as actual Forms as well? If yes, you can create Form1 with a single child: UserControl1 and Form2 with a single child: UserControl2

Hth

Upvotes: 0

Related Questions