在 2 个屏幕上最大化表单
我的客户希望我更改默认的最大化按钮功能,以在客户拥有的所有屏幕上最大化表单。我已经编写了一些代码来测量放置表单的正确矩形,但是当我将其分配给表单的 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我同意马特的观点。设置“MaximizedBounds”并不是一个好主意。
正如窗口最大化/非最大化时的事件,我会重写 WndProc 方法。在那里您可以自己处理从窗口接收到的不同命令。
要做的主要事情是为“SC_MAXIMIZE”窗口命令编写自己的代码(如上面引用的文章中所写)。您可以在那里手动设置表单的大小,例如在这种情况下,表单不会真正最大化。实际上还是正常的WindowState。为了防止用户更改此状态,您需要“捕获”一些其他窗口命令。
重写的 WndProc 方法可能如下所示:
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:
我已经能够通过直接设置
Size
属性而不是MaximizedBounds
值来使表单填满 2 个整个屏幕。I've been able to make forms fill the 2 whole screens by setting the
Size
property directly, rather than theMaximisedBounds
value.