在 2 个屏幕上最大化表单

发布于 2024-08-20 13:42:23 字数 408 浏览 12 评论 0原文

我的客户希望我更改默认的最大化按钮功能,以在客户拥有的所有屏幕上最大化表单。我已经编写了一些代码来测量放置表单的正确矩形,但是当我将其分配给表单的 MaximizedBounds 属性时,存在一些问题: 表单不在的屏幕(在我的 2 个屏幕测试中)在单击之前仅获得一个油漆,如果您单击另一个屏幕上的表单,就像您单击了它的“下方”到下面的下一个窗口。

当然,还有其他方法可以解决此问题(例如在 Event when a窗口最大化/未最大化),如果所描述的行为是一个错误,或者我的错误,我会感到受伤。在更改 MaximizedBounds 属性以使其发挥作用之前,需要做些什么吗?

My customer want me to change the default maximise-buttons functionality to maximise the form over all screens the customer have. I have already written some code to measure the correct rectangle to put the form to, but when i assign it to the MaximisedBounds attribute of the form, there are some issures: The screen (in my 2 screen tests) that the form was not on before the click get only one paint, ans if you click on the form on the other screen it is like you have clicked "under" it onto the next window beneath.

Of course there are other ways to solve this problem (like in Event when a window gets maximized/un-maximized), i wounder if the described behaviour is a bug, or my mistake. Is there anything to do before changing the MaximisedBounds attribute to make it work?

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

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

发布评论

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

评论(2

未蓝澄海的烟 2024-08-27 13:42:23

我同意马特的观点。设置“MaximizedBounds”并不是一个好主意。
正如窗口最大化/非最大化时的事件,我会重写 WndProc 方法。在那里您可以自己处理从窗口接收到的不同命令。

要做的主要事情是为“SC_MAXIMIZE”窗口命令编写自己的代码(如上面引用的文章中所写)。您可以在那里手动设置表单的大小,例如在这种情况下,表单不会真正最大化。实际上还是正常的WindowState。为了防止用户更改此状态,您需要“捕获”一些其他窗口命令。

重写的 WndProc 方法可能如下所示:

    protected override void WndProc(ref Message m)
    {
        if(m.Msg == 0x0112) // WM_SYSCOMMAND
        {
            if(m.WParam == new IntPtr(0xF012)) //TITLE_CLICK_ONCE
            {
                // catch, this command can occur, when form starts to move
            }

            if(m.WParam == new IntPtr(0xF001) // RESIZE_ON_EDGE
            || m.WParam == new IntPtr(0xF002)
            || m.WParam == new IntPtr(0xF003)
            || m.WParam == new IntPtr(0xF004)
            || m.WParam == new IntPtr(0xF005)
            || m.WParam == new IntPtr(0xF006)
            || m.WParam == new IntPtr(0xF007)
            || m.WParam == new IntPtr(0xF008))
            {
                // catch the resizing
            }

            if(m.WParam == new IntPtr(0xF032)) // SECOND_CLICK_ON_TITLEBAR
            {
                // catch. causes a maximization (or resuming to normal window-mode)
            }

            if(m.WParam == new IntPtr(0xF030)) //SC_MAXIMIZE
            {
                // the actual point, where to enter your code
                // this command occurs, when the "Maximize"-button is pressed
            }
        }

        // maybe abort calling of the base-method at specified window-commands,
        // when you want to make your own code by simply "return;"
        base.WndProc(ref m);
    }

I'd agree with Matt. Setting the "MaximizedBounds" is not a good idea.
As written in Event when a window gets maximized/un-maximized, I would override the WndProc-method. There you can handle the different received commands from your window on your own.

The main thing to do is to write your own code for the "SC_MAXIMIZE"-windowcommand (as written in the referenced article above). There you can manually set the form's size e.g. In this case the form won't be really maximized. Actually is it still in normal WindowState. To prevent the user from changing this state you need to "catch" some other windowcommands.

The overridden WndProc method could be like this:

    protected override void WndProc(ref Message m)
    {
        if(m.Msg == 0x0112) // WM_SYSCOMMAND
        {
            if(m.WParam == new IntPtr(0xF012)) //TITLE_CLICK_ONCE
            {
                // catch, this command can occur, when form starts to move
            }

            if(m.WParam == new IntPtr(0xF001) // RESIZE_ON_EDGE
            || m.WParam == new IntPtr(0xF002)
            || m.WParam == new IntPtr(0xF003)
            || m.WParam == new IntPtr(0xF004)
            || m.WParam == new IntPtr(0xF005)
            || m.WParam == new IntPtr(0xF006)
            || m.WParam == new IntPtr(0xF007)
            || m.WParam == new IntPtr(0xF008))
            {
                // catch the resizing
            }

            if(m.WParam == new IntPtr(0xF032)) // SECOND_CLICK_ON_TITLEBAR
            {
                // catch. causes a maximization (or resuming to normal window-mode)
            }

            if(m.WParam == new IntPtr(0xF030)) //SC_MAXIMIZE
            {
                // the actual point, where to enter your code
                // this command occurs, when the "Maximize"-button is pressed
            }
        }

        // maybe abort calling of the base-method at specified window-commands,
        // when you want to make your own code by simply "return;"
        base.WndProc(ref m);
    }
在你怀里撒娇 2024-08-27 13:42:23

我已经能够通过直接设置 Size 属性而不是 MaximizedBounds 值来使表单填满 2 个整个屏幕。

I've been able to make forms fill the 2 whole screens by setting the Size property directly, rather than the MaximisedBounds value.

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