Winform开发遇到的问题之TabPage选项卡禁用

1.代码块:

       //默认加载
        private void Form1_Load(object sender, EventArgs e)
        {
            tabPage();
        }

        //选项卡默认值
        private void tabPage()
        {
            for (int i = 0; i < tab.TabCount; i++)
            {
                this.tab.TabPages[i].Tag = true;
            }
        }

        //选项卡判断
        private void tabControl1_Selecting(object sender, TabControlCancelEventArgs e)
        {
            if (!string.IsNullOrEmpty(e.TabPage.Tag.ToString()) && !Convert.ToBoolean(e.TabPage.Tag))
            {
                e.Cancel = true;
            }
        }
        //修改按钮
        private void btn_Click(object sender, EventArgs e)
        {
            int tabindex = tab.SelectedIndex;
            for (int i = 0; i < tab.TabCount; i++)
            {
                if (tabindex != i)
                {
                    this.tab.TabPages[i].Tag = false;
                }
            }

        }
        //取消或保存按钮
        private void button1_Click(object sender, EventArgs e)
        {
            tabPage();
        }

2.效果图:
Winform开发遇到的问题之TabPage选项卡禁用_第1张图片

你可能感兴趣的:(Winform开发遇到问题)