我将TextBox
附加到TabPage
的第一个TabControl
。我想在每个TextBox
上显示相同的TabPage
对象。我尝试将控件添加到tabControl
集合中,但不幸的是它无效。
private void Form1_Load(object sender, EventArgs e)
{
tabControl1.TabPages[tabControl1.SelectedIndex].Controls.Add(textBox);
}
答案 0 :(得分:1)
按钮b;
public Form1()
{
InitializeComponent();
b = new Button() { Text = "Prueba" };
}
private void Form1_Load(object sender, EventArgs e)
{
AddButtonToTabControl();
}
private void tabControl1_SelectedIndexChanged(object sender, EventArgs e)
{
AddButtonToTabControl();
}
public void AddButtonToTabControl()
{
tabControl1.SelectedTab.Controls.Add(b);
}
答案 1 :(得分:0)
我错过了两种方法。它现在正在工作!
tabControl1.Selecting += new TabControlCancelEventHandler(tabControl1_Selecting);
void tabControl1_Selecting(object sender, TabControlCancelEventArgs e)
{
tabControl1.TabPages[tabControl1.SelectedIndex].Controls.Add(textBox);
}