C#用TabControl控件如何使某个TabPage禁用

  • Post author:
  • Post category:其他


如题!比如有3个TabPage控件,要让其中一个禁用,也就是不能点开,怎么做?

查MSDN找不到,看TabControl和TabPage类的方法和属性也找不到…咋办呢?


——解决方案——————————————————–


禁用第二个选项卡…

C# code

    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
            tabControl1.Selecting += new TabControlCancelEventHandler(tabControl1_Selecting);
        }

        void tabControl1_Selecting(object sender, TabControlCancelEventArgs e)
        {
            if (e.TabPageIndex == 1) e.Cancel = true;
        }
    }

------解决方案--------------------------------------------------------
搞成这样也行...

  
  
C# code

    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
            tabControl1.Selecting += new TabControlCancelEventHandler(tabControl1_Selecting);

            tabPage2.Tag = true;
            tabPage3.Tag = true;
        }

        void tabControl1_Selecting(object sender, TabControlCancelEventArgs e)
        {
            if (e.TabPage.Tag!=null&&(bool)e.TabPage.Tag) e.Cancel = true;
        }
    }