Go homepage(回首页) Upload pictures (上传图片) Write articles (发文字帖)
The author:(作者)qqpublished in(发表于) 2014/7/11 9:18:06 C#中TabControl控件应用实例
C#中TabControl控件应用实例
TabControl控件功能TabControl控件显示多个选项卡,这些选项卡类似于笔记本中的分隔卡和档案柜文件夹中的标签。TabControl控件的选项卡中可包含图片和其他控件。此外,TabControl控件还可以用来创建一组相关属性的属性页。图1所示为TabControl控件。图1 TabControl控件2.属性TabControl控件常用属性及说明如表1所示。表1 TabControl控件常用属性及说明下面详细介绍TabPages属性,此属性获取该选项卡控件中选项卡页的集合。语法:public TabPageCollection TabPages { get; }属性值:TabControl.TabPageCollection,它包含该TabControl中的TabPage对象。说明:此集合中的选项卡页的顺序反映了选项卡在控件中出现的顺序。示例本教程来自http://www.isstudy.com/TabPages属性的使用本示例中,当程序运行时,单击【TabPages 属性】按钮,向TabPages控件中添加项。示例运行结果如图2所示。图2 TabPages属性程序主要代码如下:string strName = "功能" + Convert.ToString(this.tabControl1.TabPages.Count + 1);string strTap = "tabPage" + Convert.ToString(this.tabControl1.TabPages.Count);this.tabControl1.TabPages.Add(strTap, strName);★★★★★主程序文件完整程序代码★★★★★using System;using System.Collections.Generic;using System.Windows.Forms;namespace _8_48{static class Program{/// /// 应用程序的主入口点。/// [STAThread]static void Main(){Application.EnableVisualStyles();Application.SetCompatibleTextRenderingDefault(false);Application.Run(new frmTabControl());}}}★★★★★frmTabControl窗体设计文件完整程序代码网站源代码★★★★★using System;using System.Collections.Generic;using System.ComponentModel;using System.Data;using System.Drawing;using System.Text;using System.Windows.Forms;namespace _8_48{public partial class frmTabControl : Form{public frmTabControl(){InitializeComponent();}private void button1_Click(object sender, EventArgs e){this.tabPage1.Text = "功能1";this.tabPage2.Text = "功能2";string strName = "功能" + Convert.ToString(this.tabControl1.TabPages.Count + 1);string strTap = "tabPage" + Convert.ToString(this.tabControl1.TabPages.Count);this.tabControl1.TabPages.Add(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{/// /// 必需的设计器变量。本教程来自http://www.isstudy.com//// private System.ComponentModel.IContainer components = null;/// /// 清理所有正在使用的资源。/// /// 如果应释放托管资源,为 true;否则为 false。protected override void Dispose(bool disposing){if (disposing && (components != null)){components.Dispose();}base.Dispose(disposing);}#region Windows 窗体设计器生成的代码/// /// 设计器支持所需的方法 - 不要/// 使用代码编辑器修改此方法的内容。/// private void InitializeComponent(){this.tabControl1 = new System.Windows.Forms.TabControl();this.tabPage1 = new System.Windows.Forms.TabPage();this.tabPage2 = new System.Windows.Forms.TabPage();this.button1 = new System.Windows.Forms.Button();this.tabControl1.SuspendLayout();this.SuspendLayout();//// tabControl1//this.tabControl1.Controls.Add(this.tabPage1);
赞