winform tabControl增加选项卡后在选项卡中添加东西
Form form = new Form();
tabPage1.Controls.Add(form);
form.Show(); 加载窗体也知道。
但是合起来就出问题了 展开
private void button1_Click(object sender, EventArgs e)
{
this.IsMdiContainer = true; //如果你要加入一个窗口放在tabpage里,原窗口要设置成mdi父窗口
TabPage page1 = new TabPage(); //建立新的tabpage
page1.Text = "new Page";
Form f = new Form(); //建立新的窗口
TextBox[] boxs = new TextBox[3]; //建立三个textbox
int textTop = 10;
for (int i = 0; i < boxs.Length; i++)
{
boxs[i] = new TextBox();
boxs[i].Parent = f;
boxs[i].Left = 10;
boxs[i].Top = textTop;
textTop += 25;
}
tabControl1.TabPages.Add(page1); //把tabpage加入到tabcontrol里
f.MdiParent = this; //新窗口的父窗口是原窗口
f.Parent = page1;
f.Dock = DockStyle.Fill;
f.Show();
tabControl1.SelectedTab = page1;
}
-----------------------------------------------------------------------------------------------------------