设置 Windows 窗体窗口的窗口状态的提示

发布于 2024-08-22 12:53:53 字数 204 浏览 7 评论 0原文

我有一个可打开 MDI 子窗体的 Windows 窗体应用程序。当我选择这些表单时,我需要将其窗口状态设置或呈现为最大化。问题是,当我在打开的窗体之间导航时,它会恢复到正常窗口状态,而当我再次将窗口状态设置为最大化时,它会显示从正常状态到最大化状态的转换,而且看起来不太好。

如何创建具有 MDI 父窗体并在最大化窗口状态下打开许多 MDI 子窗体的 Windows 应用程序?

I have a Windows Forms application that opens MDI child forms. When I select those forms, I need to set or render its windowstate to Maximized. The problem is, when I navigate between the open forms, it reverts back to the normal window state, and when I set the window state to maximized again, it shows the transition from normal to maximized state and it doesn't look nice.

How can a Windows application be created that have an MDI parent form that opens many MDI childs in maximized window state?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

残月升风 2024-08-29 12:53:53

以下是基于使用 MDI“父窗体和子窗体范例”的答案,并具有以下假设:

  1. 您在 MDIParentForm 上有一个 MenuStrip 控件 'Dock = 'Top,并且您已经实现了自动 MDI &Window菜单处理程序,如下所述: 如何:创建 MDI 窗口使用 MenuStrip 列出

  2. 您正在创建新的子表单:

    a.没有 MaximizeBox、MinimizeBox 等,但可能有 ControlBox(用于关闭它们)

    b.这些子表单可以调整大小,也可以不调整大小:我们不会在这里考虑其含义。

  3. 您希望这些 MDIChildForm 在 MDIParent 窗体中最大化显示,但不遮挡 MDIParentForm 的菜单。

好的:假设您已经完全设计了所有子表单,“等待”:我们可能会在您的 MDIParentForm 代码中看到类似这样的代码:

    // create instances of your child forms
    Form2 f2 = new Form2();
    Form3 f3 = new Form3();
    Form4 f4 = new Form4();
    Form5 f5 = new Form5();

    private void MDIParentForm1_Load(object sender, EventArgs e)
    {
        f2.Text = "subForm1";
        f3.Text = "subForm2";
        f4.Text = "subForm3";
        f5.Text = "subForm4";

        f2.MdiParent = this;
        f3.MdiParent = this;
        f4.MdiParent = this;
        f5.MdiParent = this;

        f2.Dock = DockStyle.Fill;
        f3.Dock = DockStyle.Fill;
        f4.Dock = DockStyle.Fill;
        f5.Dock = DockStyle.Fill;

        f2.Show();
        f3.Show();
        f4.Show();
        f5.Show();
    }

此时,应用到子表单的停靠样式“填充”将使它们充满 -屏幕,并防止它们遮挡 MDIParentForm 菜单:并且该菜单将允许您自动选择哪一个位于最前面。

现在,如果您想做一些更奇特的事情:例如调整子表单的大小、平铺它们、级联它们。您必须更改这些子窗口的“Dock”属性:然后您可以使用内置的 MDI 范例窗口排列工具,如下所述:如何:排列 MDI 子窗体

如果您想创建一种类型的预定义子窗体的多个实例表单:如何创建 MDI 子表单 。 ..请参阅有关如何使用“新菜单条目:可能有用”的示例。

Here's an answer based on using the MDI "Parent Form and Child Form paradigm," with the following assumptions :

  1. you have a MenuStrip control 'Dock = 'Top on your MDIParentForm, and you've implemented the automatic MDI &Window menu handler as described in : How to: Create an MDI Window List with MenuStrip

  2. you are creating new child forms that :

    a. do not have a MaximizeBox, MinimizeBox, etc., but may have ControlBox (for closing them)

    b. these child forms may be resizable or not : we won't consider the implications of that here.

  3. You want these MDIChildForms to display maximized in the MDIParent Form, but not to obscure the MDIParentForm's menu.

Okay : assuming you have all your child Forms fully designed, "waiting in the wings" : we might see some code like this in your MDIParentForm code :

    // create instances of your child forms
    Form2 f2 = new Form2();
    Form3 f3 = new Form3();
    Form4 f4 = new Form4();
    Form5 f5 = new Form5();

    private void MDIParentForm1_Load(object sender, EventArgs e)
    {
        f2.Text = "subForm1";
        f3.Text = "subForm2";
        f4.Text = "subForm3";
        f5.Text = "subForm4";

        f2.MdiParent = this;
        f3.MdiParent = this;
        f4.MdiParent = this;
        f5.MdiParent = this;

        f2.Dock = DockStyle.Fill;
        f3.Dock = DockStyle.Fill;
        f4.Dock = DockStyle.Fill;
        f5.Dock = DockStyle.Fill;

        f2.Show();
        f3.Show();
        f4.Show();
        f5.Show();
    }

At this point, the dock style 'Fill applied to the child forms will make them full-screen, and keep them from obscuring the MDIParentForm menu : and the menu will allow you to auto-select which one is frontmost.

Now, if you want to do fancier stuff : like resizing the child Forms, tiling them, cascading them. You are going to have to change the 'Dock property of these child windows : and then you can make use of the built-in MDI paradigm window arranging facilities as described here : How to: Arrange MDI Child Forms

And if you want to create multiple instances of one type of pre-defined child form : How to Create MDI Child Forms ... see the example on how to use a 'New menu entry : may prove useful.

与之呼应 2024-08-29 12:53:53

如果您希望窗口状态始终最大化,我建议您放弃 MDI 表单。在这种情况下,TabControl 可能会工作得更好。

MDI 表单存在相当多的可用性问题,这就是它们不再常用的原因,并且往往被其他控件/选项所取代。

If you want the window state to always be maximized, I'd recommend switching away from an MDI Form. A TabControl may work better, in that case.

MDI forms have quite a few usability issues, which is why they are not commonly used anymore, and tend to be replaced with other controls/options.

如果没有你 2024-08-29 12:53:53

阅读里德的回答,尤其是您的评论后:

tabcontrol 的问题是,我有一个
每个子表单使用很多控件

也许这会有所帮助:
不要将控件放入 Winform 中。相反,将它们封装到 UserControl 中(也许通过将继承从 Form 更改为 UserControl 就可以工作了)。

现在将每个 UserControl 放在它自己的 TabPage 上并将其 Dock 属性设置为 Fill。现在,您可以单独更改每个 UserControl,而不会干扰另一个 TabPage 上的另一个控件(只要您没有建立任何连接)。

After reading Reeds answer and especially your comment:

problem with tabcontrol is, i have a
lot of controls used per child form

Maybe this will help:
Don't put your controls into a Winform. Instead encapsulate them into a UserControl (maybe it already works by changing your inheritance from Form to UserControl).

Now put every UserControl on it's own TabPage and set its Dock property to Fill. Now you are able to change each UserControl on it's own, without any interference to another control on another TabPage (as far as you don't built in any connection).

悍妇囚夫 2024-08-29 12:53:53

如果你打算放弃 MDI,你可以看看 WeifenLuoDigitalRune。这些都是免费的,对于其他选项,您可以在这里查看: http://windowsclient.net/downloads/folders/controlgallery/tags/Windows+Forms+Docking+Windows/default.aspx


编辑:

如果我没记错的话,DigitalRune允许使用 Windows 窗体作为停靠内容的容器,因此迁移工作会更小。

If you intend to give up on MDI, you could have a look at docking frameworks like WeifenLuo or DigitalRune. These are free, for other options you can have a look here: http://windowsclient.net/downloads/folders/controlgallery/tags/Windows+Forms+Docking+Windows/default.aspx


EDIT:

If I remember well, DigitalRune allows the usage of windows forms as containers for docked content so the migration effort would be smaller.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文