C# 显示选项卡时执行代码
我想在显示选项卡时对其执行一些操作 例如:C# 显示选项卡时执行代码,c#,tabs,tabcontrol,C#,Tabs,Tabcontrol,我想在显示选项卡时对其执行一些操作 例如: textBox1.SelectionStart = textBox1.Text.Length; textBox1.ScrollToCaret(); textBox3.SelectionStart = textBox3.Text.Length; textBox3.ScrollToCaret(); textBox2.SelectionStart = textBox2.Text.Length; textBox2.Focus(); 我应该把代码放在哪里以确保
textBox1.SelectionStart = textBox1.Text.Length;
textBox1.ScrollToCaret();
textBox3.SelectionStart = textBox3.Text.Length;
textBox3.ScrollToCaret();
textBox2.SelectionStart = textBox2.Text.Length;
textBox2.Focus();
我应该把代码放在哪里以确保它正确完成
选择的事件、选择的事件和输入的事件不起作用,因为它们发生在选项卡显示之前
我知道首先必须显示选项卡,然后必须执行代码。在
SelectedIndexChanged
事件中尝试
private void yourTabControl1_SelectedIndexChanged(Object sender, EventArgs e) {
textBox1.SelectionStart = textBox1.Text.Length;
textBox1.ScrollToCaret();
textBox3.SelectionStart = textBox3.Text.Length;
textBox3.ScrollToCaret();
textBox2.SelectionStart = textBox2.Text.Length;
textBox2.Focus();
}
用
tabPage
的Enter
事件来代替tabControl
怎么样?谢谢Zey,太棒了。