Reputation: 779
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
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:
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