views:

177

answers:

1

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?

+4  A: 

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);
  }
}
Hans Passant
Great! It works perfectly! Much thanks! I wonder if is there some issue about portability on other platforms than Win32...
Luca