如何处理在.NET的WinForms堆叠控件?控件、如何处理、NET、WinForms

2023-09-03 02:54:28 作者:轮回|▎只为你停留一世

我有将多个面板控制堆叠在彼此的顶部上的形式,被显示的每一个/隐藏基于所述表格上的其他选择的选项。这是一个真正的痛苦,在表单设计器,以管理为面板不表现得像一个完整的TabControl。然而,它并不像你可以使用一个的TabControl没有标签。什么是处理这一问题的最佳方法是什么?有没有像TabControl的控制,但没有标签?

I have a form that will multiple Panel controls stacked on top of each other, each one being shown/hidden based on other selected options on the form. This has been a real pain to manage in the form designer as the panels don't behave like a full TabControl. However, it doesn't look like you can use a TabControl without the tabs. What is the best way to handle this? Is there a control like the TabControl, but without the tabs?

推荐答案

您可以隐藏的标签,在设计非常方便。添加一个新类到您的项目并粘贴此code:

You can hide the tabs, very convenient in the designer. Add a new class to your project and paste this code:

using System;
using System.Windows.Forms;

public class TablessControl : 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);
  }
}