本文介绍了隐藏 TabControl 按钮以管理堆叠的面板控件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要处理包含各种数据掩码的多个面板.每个面板都应使用 TreeView 控件可见.

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.

实际上这不是很舒服,尤其是在 UI 设计器中,因为当我添加一个全新的面板时,我必须调整每个面板的大小,然后对其进行设计...

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...

一个好的解决方案是使用 TabControl,并且每个面板都包含在一个 TabPage 中.但是我找不到任何方法来隐藏 TabControl 按钮,因为我已经有一个用于选择项目的 TreeView.

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.

另一种解决方案是 ipotethic "StackPanelControl",其中面板使用堆栈排列,但我在任何地方都找不到.

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

处理这种 UI 的最佳解决方案是什么?

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

推荐答案

您需要一点 Win32 API 魔法.选项卡控件发送 TCM_ADJUSTRECT 消息以允许应用调整选项卡大小.向您的项目添加一个新类并粘贴如下所示的代码.编译.将新控件从工具箱顶部拖放到表单上.

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.

您将在设计时获得标签,以便您可以轻松地在页面之间切换.选项卡在运行时隐藏,使用 SelectedIndex 或 SelectedTab 属性在视图"之间切换.

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

这篇关于隐藏 TabControl 按钮以管理堆叠的面板控件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-01 07:13