繁体   English   中英

如何在tabcontrol中禁用标签页眉

[英]How to disable tab headers in tabcontrol

我有一个制作项目的向导,我使我们成为一个tabcontrol。 我有一些按钮可以转到下一个选项卡或上一个选项卡。 我现在的问题是,即使认为必填字段的按钮上已经过验证,您仍然可以通过单击选项卡标题在选项卡之间切换。 如果禁用tabcontrol,则用户也无法使用选项卡中的任何内容。 我能解决这个问题吗?

更新:向导表单的所有代码

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;

using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace WorldEstablisher
{
    public partial class ProjectWizard : Form
    {
        #region variables

    public Form1 MainForm { get; set; }

    #endregion

    #region constructor and page load

    public ProjectWizard(Form1 form)
    {
        InitializeComponent();
        MainForm = form;
    }

    private void ProjectWizard_Load(object sender, EventArgs e)
    {
    }
    #endregion

    #region navigation

    private void nextButton_Click(object sender, EventArgs e)
    {
        if (tabs.SelectedIndex == 0)//field validation tab 1
        {
            if (folderLocationTextBox.Text != "" && worldNameTextBox.Text != "")
            {
                backButton.Visible = true;
                tabs.SelectedIndex = tabs.SelectedIndex + 1;
            }
        }

        if (tabs.SelectedIndex == 1)//field validation tab 2
        {
            if (authorTextBox.Text != "")
            {
                tabs.SelectedIndex = tabs.SelectedIndex + 1;
            }
        }

        if (tabs.SelectedIndex == 2)
        {
            finishButton.Visible = true;
        }
    }

    private void backButton_Click(object sender, EventArgs e)
    {
        if (tabs.SelectedIndex != 0)
        {
            tabs.SelectedIndex = tabs.SelectedIndex - 1;
            if (tabs.SelectedIndex == 0)//Make the back button invisible
            {
                backButton.Visible = false;
            }
            if (tabs.SelectedIndex != 2)//Make the finish button invisible
            {
                finishButton.Visible = false;
            }
        }
    }

    private void finishButton_Click(object sender, EventArgs e)
    {
        World world = new World("test");
        MainForm.CurrentWorld = world;
        this.Close();
    }

    #endregion

    private void selectFolderButton_Click(object sender, EventArgs e)
    {
        if (folderBrowser.ShowDialog() == DialogResult.OK)
        {
            folderLocationTextBox.Text = folderBrowser.SelectedPath;
        }
    }
}
}

应该有一个更好的方法,但是在TabControlSelectedIndexChanged事件中,您可以将SelectedTab设置为所需的TabPage 当用户单击您的导航按钮时,跟踪当前的TabPage

private TabPage currentTabPage;
private void tabControl1_SelectedIndexChanged(object sender, EventArgs e)
{
    tabControl1.SelectedTab = currentTabPage;
}

由于您基本上将消除TabControl的内置导航,因此我将重新考虑您的设计。 使用根据按钮导航机制显示或隐藏的一组Panel对象。 通过向用户显示他们从未使用过的选项卡按钮,不要使用户感到困惑。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM