简体   繁体   English

如何在tabcontrol中禁用标签页眉

[英]How to disable tab headers in tabcontrol

I have a wizard to make a project, I make us e of a tabcontrol. 我有一个制作项目的向导,我使我们成为一个tabcontrol。 I have buttons to go to the next tab or the previous. 我有一些按钮可以转到下一个选项卡或上一个选项卡。 My problem now is that even thought there is validation on the buttons for required field, you can still switch between the tabs by clicking the tab headers. 我现在的问题是,即使认为必填字段的按钮上已经过验证,您仍然可以通过单击选项卡标题在选项卡之间切换。 If I disable the tabcontrol, the user can't use whatever is inside the tabs either. 如果禁用tabcontrol,则用户也无法使用选项卡中的任何内容。 Can I solve this? 我能解决这个问题吗?

UPDATE: all the code of the wizard form 更新:向导表单的所有代码

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

There should be a better way to do this, but in the SelectedIndexChanged event for the TabControl you can set the SelectedTab to be whichever TabPage you want it to be. 应该有一个更好的方法,但是在TabControlSelectedIndexChanged事件中,您可以将SelectedTab设置为所需的TabPage Track the current TabPage when the user clicks on your navigation buttons. 当用户单击您的导航按钮时,跟踪当前的TabPage

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

Since you'd be basically eliminating the built-in navigation of a TabControl , I'd rethink your design. 由于您基本上将消除TabControl的内置导航,因此我将重新考虑您的设计。 Use a stack of Panel objects that you show or hide based on your button navigation mechanism. 使用根据按钮导航机制显示或隐藏的一组Panel对象。 Don't confuse the user by showing them tab buttons that they can't ever use. 通过向用户显示他们从未使用过的选项卡按钮,不要使用户感到困惑。

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

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