How do I create a TabControl with no tab headers?

后端 未结 5 1546
深忆病人
深忆病人 2020-12-15 14:12

How do I make a tab manager that doesn\'t show the tab headers?

This is a winforms application, and the purpose of using a tab manager is so the display content can

相关标签:
5条回答
  • 2020-12-15 14:44

    After the edit and comments made the question more clear, I think the normal way to handle this is to use multiple panels rather than tabs.

    0 讨论(0)
  • 2020-12-15 14:48

    Along with everybody else, I find your question a bit confusing. I've used this method found here before. Using this way you have a single property you can change as to whether you want to show the tab headers or not.

    0 讨论(0)
  • 2020-12-15 14:54

    I guess, that using panels is the simplest solution. In addition, I suggest using my (free, opensource) VisualStateManager to simplify switching and eliminate lots of .Enabled = true horrors.

    Package is available on Nuget.

    Just write this code:

    // Contains and propagates information about current page
    private SwitchCondition<int> settingPageCondition;
    // Controls state of specific controls basing on given SwitchCondition
    private VisualStateSwitchController<int> settingPageController;
    
    // (...)
    
    private void InitializeActions()
    {
        // Initialize with possible options
        settingPageCondition = new SwitchCondition<int>(0, 1);
    
        settingPageController = new VisualStateSwitchController<int>(
            null,                  // Enabled is not controlled
            null,                  // Checked is not controlled
            settingPageCondition,  // Visible is controller by settingPageCondition
            new SwitchControlSet<int>(0, pGeneral),   // State 0 controls pGeneral
            new SwitchControlSet<int>(1, pParsing));  // State 1 controls pParsing
    }
    
    // (...)
    
    public void MainForm()
    {
        InitializeComponent();
        InitializeActions();
    }
    
    // (...)
    
    // Wat to set specific page
    settingPageCondition.Current = 0;
    
    0 讨论(0)
  • 2020-12-15 14:56

    Hiding the tabs on a standard TabControl is pretty simple, once you know the trick. The tab control is sent a TCM_ADJUSTRECT message when it needs to adjust the tab size, so we just need to trap that message. (I'm sure this has been answered before, but posting the code is easier than searching for it.)

    Add the following code to a new class in your project, recompile, and use the CustomTabControl class instead of the built-in control:

    class CustomTabControl : TabControl
    {
        private const int TCM_ADJUSTRECT = 0x1328;
    
        protected override void WndProc(ref Message m)
        {
            // Hide the tab headers at run-time
            if (m.Msg == TCM_ADJUSTRECT && !DesignMode)
            {
                m.Result = (IntPtr)1;
                return;
            }
    
            // call the base class implementation
            base.WndProc(ref m);
        }
    }
    

    (Code sample originally taken from Dot Net Thoughts.)

    Note that this will not work properly for tab headers positioned on the sides or the bottom. But not only does that just look weird, you won't be able to see the tabs at run-time anyway. Just put them on the top where they belong.

    0 讨论(0)
  • 2020-12-15 14:57

    Right, if it's web application, you can build your own DIV with the same placement and hide/show as per your needs.

    0 讨论(0)
提交回复
热议问题