设计具有多个面板的Windows.Form->如何隐藏一个面板(如PS层) [英] Designing Windows.Form with multiple panels -> How to hide one panel (like a PS layer)

查看:121
本文介绍了设计具有多个面板的Windows.Form->如何隐藏一个面板(如PS层)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在Visual Studio 2008 Form Designer中像PS中的一层一样隐藏一个面板?否则,有人可以推荐另一种更好的方法来设计多个必须由用户点击的屏幕"吗?

How can I hide one panel in Visual Studio 2008 Form Designer like a layer in PS? Otherwise, can someone recommend another better method to design multiple "screens" that must be clicked through by the user?

推荐答案

您所描述的是一个向导,您可能想研究

What you describe is a wizard, and you might want to investigate the approach from Eric J.

但是,当我想在UI的同一空间中拥有多个面板并且想要在设计器中进行切换时,我喜欢使用TabControl并隐藏TabControl上的选项卡.这样一来,用户界面在设计时就更易于管理,并且代码在运行时在各选项卡之间切换非常简单.

However, when I have cases where I want to have multiple panels in the same space within my UI and I want to switch between them in the designer, I like to use a TabControl and hide the tabs on the TabControl. This makes the UI easier to manage at design time and the code is pretty simple to switch between the tabs at run time.

我做了一个非常简单的自定义控件,该控件从TabControl派生而来,称为HiddenTabsControl.该类仅覆盖WndProc,并让TabControl基类处理其他所有内容.您需要做的只是:

I made a custom control that derives from TabControl called HiddenTabsControl that is very simple. The class only overrides the WndProc and lets the TabControl base class handle everything else. All you need to do is:

  • 向您的项目添加新项
  • 选择自定义控件,
  • 将其命名为HiddenTabsControl.
  • 将基类更改为TabControl,删除Visual Studio添加的构造方法和OnPaint替代.
  • 将WndProc的此替代复制到类中:

  • Add a New Item to your project
  • Choose Custom Control,
  • Name it something like HiddenTabsControl.
  • Change the base Class to TabControl, remove the Constructor and the OnPaint override that Visual Studio added.
  • Copy this override for WndProc into the class:

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

现在,您可以在设计器中更改选项卡并轻松设计UI,并且可以在代码中处理事件以根据需要更改选项卡.更改选定的"选项卡很容易:

Now you can change tabs in the designer and design the UI easily and in the code you can handle events to change tabs as needed. Changing the Selected tab is easily done with:

this.hiddenTabsControl.SelectedTab = this.tabPageYouWantVisible;

删除选项卡的一个副作用是,在构造控件时,选项卡所占据的空间.删除它们将使HiddenTabsControl占用的空间缩小.我通常将HiddenTabsControl的Anchor设置为底部,以防止其缩小.

One side effect of removing the tabs is the space that the tabs occupy when the control is constructed. Removing them will make the space the HiddenTabsControl occupies change by shrinking it. I usually set the Anchor of the HiddenTabsControl to bottom to keep it from shrinking.

这篇关于设计具有多个面板的Windows.Form->如何隐藏一个面板(如PS层)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆