Hide TabControl buttons to manage stacked Panel controls

三世轮回 提交于 2019-11-26 02:23:31

问题


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?


回答1:


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



回答2:


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;


来源:https://stackoverflow.com/questions/2798215/hide-tabcontrol-buttons-to-manage-stacked-panel-controls

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!