C# TabControl TabPage 更改
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/831330/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
C# TabControl TabPage Change
提问by Goober
How do I change the tabpage being displayed in my tabcontrol programmatically?
如何以编程方式更改 tabcontrol 中显示的 tabpage?
采纳答案by Joshua Belden
Either by tabControl1.SelectedIndex which is an integer or if you have a reference to a particular tab, tabControl1.SelectedTab.
通过 tabControl1.SelectedIndex 这是一个整数,或者如果您有对特定选项卡的引用,tabControl1.SelectedTab。
If you wanted the first one selected:
如果您想选择第一个:
tabControl1.SelectedIndex = 0;
回答by amalgamate
Other alternatives to the accepted answer:
已接受答案的其他替代方案:
tabControl1.SelectedTab = MyTabPage;
or tabControl1.SelectTab("NameOfTabToActivate");
或者 tabControl1.SelectTab("NameOfTabToActivate");
or tabControl1.SelectTab(IndexOfTab);
或者 tabControl1.SelectTab(IndexOfTab);
or tabControl1.SelectTab(TabObject);
或者 tabControl1.SelectTab(TabObject);
(I stole this answer from this post: Activate tabpage of TabControl)
(我从这篇文章中窃取了这个答案:Activate tabpage of TabControl)