Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Hide TabControl buttons to manage stacked Panel controls

I need to handle multiple panels, containing variuous data masks. Each panel shall be visible using a TreeView control.

At this time, I handle the panels visibility manually, by making the selected one visible and bring it on top.

Actually this is not much confortable, especially in the UI designer, since when I add a brand new panel I have to resize every panel and then design it...

A good solution would be using a TabControl, and each panel is contained in a TabPage. But I cannot find any way to hide the TabControl buttons, since I already have a TreeView for selecting items.

Another solution would be an ipotethic "StackPanelControl", where the Panels are arranged using a stack, but I couldn't find it anywhere.

What's the best solution to handle this kind of UI?

like image 735
Luca Avatar asked May 09 '10 15:05

Luca


2 Answers

You need a wee bit of Win32 API magic. The tab control sends the TCM_ADJUSTRECT message to allow the app to adjust the tab size. Add a new class to your project and paste the code shown below. Compile. Drop the new control from the top of the toolbox onto your form.

You'll get the tabs at design time so you can easily switch between pages. The tabs are hidden at runtime, use the SelectedIndex or SelectedTab property to switch between "views".

using System;
using System.Windows.Forms;

class StackPanel : TabControl {
  protected override void WndProc(ref Message m) {
    // Hide tabs by trapping the TCM_ADJUSTRECT message
    if (m.Msg == 0x1328 && !DesignMode) m.Result = (IntPtr)1;
    else base.WndProc(ref m);
  }
}
like image 156
Hans Passant Avatar answered Nov 20 '22 16:11

Hans Passant


A good solution would be using a TabControl, and each panel is contained in a TabPage. But I cannot find any way to hide the TabControl buttons, since I already have a TreeView for selecting items.

For the above, You need to set the following properties of TabControl.

tabControl.Multiline = true;
tabControl.Appearance = TabAppearance.Buttons;
tabControl.ItemSize = new System.Drawing.Size(0, 1);
tabControl.SizeMode = TabSizeMode.Fixed;
tabControl.TabStop = false;
like image 27
user3840507 Avatar answered Nov 20 '22 17:11

user3840507