C#tabcontrol如何指定某个tabItem为默认页
// Selects tabPage2 using SelectedTab.
this.tabControl1.SelectedTab = tabPage2;
参考链接
TabControl.SelectedTab 属性 (System.Windows.Forms) | Microsoft Learnhttps://learn.microsoft.com/zh-cn/dotnet/api/system.windows.forms.tabcontrol.selectedtab?view=netframework-4.8&devlangs=csharp&f1url=%3FappId%3DDev17IDEF1%26l%3DZH-CN%26k%3Dk(System.Windows.Forms.TabControl.SelectedTab)%3Bk(TargetFrameworkMoniker-.NETFramework%2CVersion%253Dv4.8)%3Bk(DevLang-csharp)%26rd%3Dtrue
下面的代码示例创建一个包含两TabPage个TabControl对象的对象。 属性 SelectedTab 设置为 tabPage2
当前选定的选项卡页。
using System.Drawing;
using System.Windows.Forms;
public class Form1 : Form
{
private TabControl tabControl1;
private TabPage tabPage1;
private TabPage tabPage2;
private void MyTabs()
{
this.tabControl1 = new TabControl();
this.tabPage1 = new TabPage();
this.tabPage2 = new TabPage();
this.tabControl1.Controls.AddRange(new Control[] {
this.tabPage1,
this.tabPage2});
this.tabControl1.Padding = new Point(15, 10);
this.tabControl1.Location = new Point(35, 25);
this.tabControl1.Size = new Size(220, 220);
// Selects tabPage2 using SelectedTab.
this.tabControl1.SelectedTab = tabPage2;
this.tabPage1.Text = "tabPage1";
this.tabPage2.Text = "tabPage2";
this.Size = new Size(300, 300);
this.Controls.AddRange(new Control[] {
this.tabControl1});
}
public Form1()
{
MyTabs();
}
static void Main()
{
Application.Run(new Form1());
}
}
特此记录
anlog
2024年11月28日