How to create TabControl without tab headers?

How to create a tab manager that does not display tab headers?

This is a winforms application, and the purpose of using the tab manager is that the contents of the screen can only be changed with code. This is useful for menus where various menu options change the contents of the screen.

+4
source share
5 answers

Hiding tabs on the standard TabControl pretty easy once you know the trick. The tab control sends a TCM_ADJUSTRECT message when it needs to adjust the size of the tab, so we just need to catch this message. (I'm sure this was answered before, but posting the code is easier than finding it.)

Add the following code to the 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); } } 

(Sample code originally taken from Dot Net Thoughts .)

Please note that this will not work properly for tab titles located on the sides or bottom. But it doesn’t just look weird, you won’t be able to see the tabs at runtime anyway. Just put them on top where they belong.

+15
source

That's right, if it is a web application, you can create your own DIV with the same placement and hide / show according to your needs.

+1
source

Along with everyone else, I find your question a bit confusing. I have already used this method here . Using this method, you have one property that you can change as to whether you want to show tab headers or not.

+1
source

After editing and commenting, the question became clearer, I believe that the normal way to handle this is to use multiple panels, not tabs.

0
source

I think using panels is the easiest solution. In addition, I suggest using my (free, openource) VisualStateManager to simplify switching and eliminate a lot of horrors .Enabled = true .

The 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
source

Source: https://habr.com/ru/post/1338617/


All Articles