2024年2月9日发(作者:)

TabControl控件显示多个选项卡,这些选项卡类似于笔记本中的分隔卡和档案柜文件夹中的标签。TabControl控件的选项卡中可包含图片和其他控件。此外,TabControl控件还可以用来创建一组相

TabControl控件

功能

TabControl控件显示多个选项卡,这些选项卡类似于笔记本中的分隔卡和档案柜文件夹中的标签。TabControl控件的选项卡中可包含图片和其他控件。此外,TabControl控件还可以用来创建一组相关属性的属性页。图1所示为TabControl控件。

图1 TabControl控件

2.属性

TabControl控件常用属性及说明如表1所示。

表1 TabControl控件常用属性及说明

下面详细介绍TabPages属性,此属性获取该选项卡控件中选项卡页的集合。

语法:

public TabPageCollection TabPages { get; }

属性值:eCollection,它包含该TabControl中的TabPage对象。

说明:此集合中的选项卡页的顺序反映了选项卡在控件中出现的顺序。

示例本教程来自/

TabPages属性的使用

本示例中,当程序运行时,单击【TabPages 属性】按钮,向TabPages控件中添加项。示例运行结果如图2所示。

图2 TabPages属性

程序主要代码如下:

string strName = "功能" + ng( +

1);

string strTap = "tabPage" + ng();

(strTap, strName);

★★★★★主程序文件完整程序代码★★★★★

using System;

using c;

using ;

namespace _8_48

{

static class Program

{

///

/// 应用程序的主入口点。

///

[STAThread]

static void Main()

{

VisualStyles();

patibleTextRenderingDefault(false);

(new frmTabControl());

}

}

}

★★★★★frmTabControl窗体设计文件完整程序代码网站源代码★★★★★

using System;

using c;

using entModel;

using ;

using g;

using ;

using ;

namespace _8_48

{

public partial class frmTabControl : Form

{

public frmTabControl()

{

InitializeComponent();

}

private void button1_Click(object sender, EventArgs e)

{

= "功能1";

= "功能2";

string strName = "功能" + ng( +

1);

string strTap = "tabPage" + ng();

(strTap, strName);

}

private void tabPage1_Click(object sender, EventArgs e)

{

}

private void frmTabControl_Load(object sender, EventArgs e)

{

}

}

}

★★★★frmTabControl窗体代码文件完整程序代码★★★★★

namespace _8_48

{

partial class frmTabControl

{

///

/// 必需的设计器变量。本教程来自/

///

private iner components = null;

///

/// 清理所有正在使用的资源。

///

/// 如果应释放托管资源,为 true;否则为 false。

protected override void Dispose(bool disposing)

{

if (disposing && (components != null))

{

e();

}

e(disposing);

}

#region Windows 窗体设计器生成的代码

///

/// 设计器支持所需的方法 - 不要

/// 使用代码编辑器修改此方法的内容。

///

private void InitializeComponent()

{

trol1 = new trol();

e1 = new e();

e2 = new e();

1 = new ();

dLayout();

dLayout();

//

// tabControl1

//

(e1);

(e2); on = new

(53, 38); = tabControl1;

edIndex = 0;

(e2);

on = new (53, 38);

= "tabControl1";

edIndex = 0;

= new (271, 127);

ex = 0;

//

// tabPage1

//

on = new (4, 21);

= "tabPage1";

g = new g(3);

= new (263, 102);

ex = 0;

= "tabPage1";

ualStyleBackColor = true;

+= new andler(e1_Click);

//

// tabPage2

//

on = new (4, 21);

= "tabPage2";

g = new g(3);

= new (263, 102);

ex = 1;

= "tabPage2";

ualStyleBackColor = true;

//

// button1

//本教程来自/

on = new (53, 193);

= "button1";

= new (154, 23);

ex = 1;

= "TabPages属性";

ualStyleBackColor = true;

+= new andler(1_Click);

//

// frmTabControl

//

aleDimensions = new (6F, 12F);

aleMode = ;

Size = new (416, 266);

(1);

(trol1);

= "frmTabControl";

= "frmTabControl";

+= new andler(Control_Load);

Layout(false);

Layout(false);

}

#endregion

private trol tabControl1;

private e tabPage1;

private e tabPage2;

private button1;

}

}

3.事件

Click事件在单击选项卡时发生。

示例

Click事件

本示例中,当程序运行时,单击【第一选项卡】按钮,弹出对话框,显示“你好”字样。

程序主要代码如下:

private void tabPage1_Click(object sender, EventArgs e)

{

("你好");

}

完整程序代码如下:

★★★★★主程序文件完整程序代码网站源代码★★★★★

using System;

using c;

using ;

namespace _8_48

{

static class Program

{

///

/// 应用程序的主入口点。

///

[STAThread]

static void Main()

{

VisualStyles();

patibleTextRenderingDefault(false);

(new frmTabControl());

}

}

}

★★★★frmTabControl窗体设计文件完整程序代码★★★★★

using System;

using c;

using entModel;

using ;

using g;

using ;

using ;

namespace _8_48

{

public partial class frmTabControl : Form

{

public frmTabControl()

{

InitializeComponent();

}

private void button1_Click(object sender, EventArgs e)

{

= "功能1";

= "功能2";

string strName = "功能" + ng( +

1);

string strTap = "tabPage" + ng();

(strTap, strName);

}

private void tabPage1_Click(object sender, EventArgs e)

{

("你好");

}

private void frmTabControl_Load(object sender, EventArgs e)

{

}

private void tabControl1_Click(object sender, EventArgs e)

{

("你好");

}

}

}

★★★★★frmTabControl窗体代码文件完整程序代码★★★★★

namespace _8_48

{

partial class frmTabControl

{

///

/// 必需的设计器变量。

///

private iner components = null;

///

/// 清理所有正在使用的资源。

/// /summary /// param name=disposing如果应释放托管资源,为 true;否则为

false。/param protected override void Dispose(bool disposing) { if (disposing

(components != null)) { component

///

/// 如果应释放托管资源,为 true;否则为 false。

protected override void Dispose(bool disposing)

{

if (disposing && (components != null))

{

e();

}

e(disposing);

}

#region Windows 窗体设计器生成的代码

///

/// 设计器支持所需的方法 - 不要

/// 使用代码编辑器修改此方法的内容。

///

本教程来自/

private void InitializeComponent()

{

trol1 = new trol();

e1 = new e();

e2 = new e();

1 = new ();

dLayout();

dLayout();

//

// tabControl1

//

(e1);

(e2);

on = new (53, 38);

= "tabControl1";

edIndex = 0;

= new (271, 127);

ex = 0;

+= new andler(trol1_Click);

//

// tabPage1

//

on = new (4, 21);

= "tabPage1";

g = new g(3);

= new (263, 102);

ex = 0;

= "tabPage1";

ualStyleBackColor = true;

+= new andler(e1_Click);

//

// tabPage2

//

on = new (4, 21);

= "tabPage2";

g = new g(3);

= new (263, 102);

ex = 1;

= "tabPage2";

ualStyleBackColor = true;

//

// button1

//

on = new (53, 193);

= "button1";

= new (154, 23);

ex = 1;

= "TabPages属性";

ualStyleBackColor = true;

+= new andler(1_Click);

//

// frmTabControl

//本教程来自/

aleDimensions = new (6F, 12F);

aleMode = ;

Size = new (416, 266);

(1);

(trol1);

= "frmTabControl";

= "frmTabControl";

+= new andler(Control_Load);

Layout(false);

Layout(false);

}

#endregion

private trol tabControl1;

private e tabPage1;

private e tabPage2;

private button1;

}

}