C# 手动添加响应函数

来源:互联网 发布:java web后端 编辑:程序博客网 时间:2024/05/23 15:44
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;


namespace UItest
{
    public partial class Form1 : Form
    {
        private readonly TabControl tabControl1;


        public Form1()
        {
            tabControl1 = new TabControl();
            tabControl1.Parent = this;
            var tabpage = new TabPage();
            tabpage.Text = "page";
            tabControl1.TabPages.Add(tabpage);
            tabControl1.TabPages.Add(tabpage);
            tabControl1.Dock = DockStyle.Fill;


            //注册响应函数
            tabControl1.Selected += new System.Windows.Forms.TabControlEventHandler(tabControl1_Selected);
            InitializeComponent();       
        }


        private void tabControl1_Selected(object sender, TabControlEventArgs e)
        {
            if (tabControl1.TabCount - 1 == e.TabPageIndex)
            {
                tabControl1.TabPages.Add(e.TabPage.Text);
                e.TabPage.Text = "选项" + e.TabPageIndex;
            }
        }






    }

}



0 0