且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

被最大化preventing WinForm的?

更新时间:2023-02-06 15:08:14

有实际工作中两个完全不同的问题在这里。当然,它们看起来基本上是从功能的角度一样,但是从实现模型的角度来看(因为Windows本身会自然地使用),他们是不相关的。

There are actually two completely separate issues at work here. Granted, they look basically the same from a functional perspective, but from an implementation-model perspective (as Windows itself would naturally use) they are unrelated.

正如其他人回答,您可以prevent的形式被最大化通过设置它的MaximizeBox$c$c>属性。这消除了WS_MAXIMIZEBOX$c$c>风格形式的基础窗口,其中prevents窗口管理器,从允许将窗口最大化上。它禁用窗口的标题栏中的最大化框(一个最小化框和关闭框之间),禁用窗口/系统菜单上的最大化选项,并最大限度地提高,我可能已经忘记了一个窗口的任何其他方法。

As others have answered, you can prevent your form from being maximized by setting its MaximizeBox property to false. This removes the WS_MAXIMIZEBOX style on the form's underlying window, which prevents the window manager from allowing the window to be maximized. It disables the maximize box on the window's caption bar (the one between the minimize box and the close box), disables the "Maximize" option on the window/system menu, and any other methods of maximizing a window that I may have forgotten.

不过,这无关与赢骨节病> + ↑ 键盘快捷键,它调用的 Aero对齐的一样会拖动窗口到神奇的位置坐了屏幕的边缘。窗口管理器,无论是作为一个bug或航空快的特点的结果,仍然可以让你有效的最大化不应以其他方式最大化的窗口。设置 MaximizeBox 属性不影响这一点,所以如果你真的从改变窗口的大小这样想prevent用户,您将需要禁用Aero对齐的在你的窗口效果。

However, this has nothing to do with the Win+ keyboard shortcut, which invokes Aero Snap the same as would dragging the window to the the magic position sat the edges of the screen. The window manager, whether as a result of a bug or a feature of Aero Snap, still allows you to effectively "maximize" windows that should not otherwise be maximized. Setting the MaximizeBox property doesn't affect this, so if you truly want to prevent the user from changing the window's size this way, you will need to disable Aero Snap's effect on your window.

不幸的是,还有的以编程方式禁用Aero对齐在每个窗口或每个进程的基础上没有一种方法(至少,据我所知)(另见this相关的问题)。如果用户有Aero对齐启用,你可以假设,他们希望这种行为和应用程序不应该乱动了。你能做的唯一一件事就是完全禁用调整你的窗口。在的WinForms,你这样做,通过设置FormBorderStyle$c$c>属性设置为下列之一: FormBorderStyle.FixedSingle FormBorderStyle.Fixed3D FormBorderStyle。 FixedDialog 。如果你还想要你的窗口,调整大小以其他方式,你需要写code到手动处理,这是不是一个特别容易的事。

Unfortunately, there's no method (at least, not to my knowledge) of programmatically disabling Aero Snap on a per-window or per-process basis (also see this related question). If the user has Aero Snap enabled, you can assume that they want that behavior and applications aren't supposed to tamper with it. The only thing you can do is completely disable resizing your window. In WinForms, you do that by setting the FormBorderStyle property to one of the following: FormBorderStyle.FixedSingle, FormBorderStyle.Fixed3D, or FormBorderStyle.FixedDialog. If you still want your window to be resizable in other ways, you will need to write the code to handle that manually, which is not a particularly easy task.

因此​​,我鼓励你仔细考虑这是否是真的有必要。所有其他非最大化的窗口做到这一点只需通过设置 MaximizeBox 属性(或做在他们的UI框架的等价物),这意味着他们仍然可以有效地通过Aero对齐最大化。如果这适用于其他人的窗口,包括那些Windows本身的一部分,它应该为你工作。

Thus, I encourage you to very carefully consider whether this is really necessary. All other non-maximizable windows accomplish this simply by setting the MaximizeBox property (or doing the equivalent in their UI framework), which means that they can still be effectively maximized via Aero Snap. If this works for everyone else's windows, including those that are part of Windows itself, it should probably work for you.