C# 手動添加響應函數

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;
            }
        }






    }

}



發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章