被最大化preventing WinForm的? [英] Preventing Winform from being maximized?

查看:96
本文介绍了被最大化preventing WinForm的?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想prevent被最大化我的桌面应用程序。它不应该成为最大化以任何方式 - 通过双击标题栏,或者通过单击的Windows +向上箭头的键盘等上

- >我禁用这两个在 MaximizeBox MinimizeBox
- >我还设置了 MAXIMUMSIZE 的minimumSize 我​​的WinForm

不过,当我preSS 的Windows +向上的箭头,我赢形式班次屏幕到左上角,我的意思是它得到最大化。 所以,请告诉我,任何方式prevent这件事情发生......

I want to prevent my desktop application from being maximized. It should not become maximized by any means - by double clicking on title bar, or by clicking Windows + Up arrow on the keyboard, etc.

-> I disable both the MaximizeBox and MinimizeBox.
-> I also set the MaximumSize and MinimumSize for my WinForm

Still when I press Windows + Up arrow, my win form Shifts to top left of the screen, I mean it gets maximized. So please tell me any way to prevent this thing happening...

推荐答案

有实际工作中两个完全不同的问题在这里。当然,它们看起来基本上是从功能的角度一样,但是从实现模型的角度来看(因为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的形式被最大化通过设置它的<一个href="http://msdn.microsoft.com/en-us/library/system.windows.forms.form.maximizebox.aspx"><$c$c>MaximizeBox属性。这消除了<一href="http://msdn.microsoft.com/en-us/library/windows/desktop/ms632600.aspx"><$c$c>WS_MAXIMIZEBOX风格形式的基础窗口,其中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.

不过,这无关与<大骨节病>赢 + <大骨节病>&uarr; 键盘快捷键,它调用的 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对齐在每个窗口或每个进程的基础上没有一种方法(至少,据我所知)(另见<一href="http://stackoverflow.com/questions/2470685/how-do-you-disable-aero-snap-in-an-application">this相关的问题)。如果用户有Aero对齐启用,你可以假设,他们希望这种行为和应用程序不应该乱动了。你能做的唯一一件事就是完全禁用调整你的窗口。在的WinForms,你这样做,通过设置<一href="http://msdn.microsoft.com/en-us/library/system.windows.forms.form.formborderstyle.aspx"><$c$c>FormBorderStyle属性设置为下列之一: 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.

这篇关于被最大化preventing WinForm的?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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