窗口最大化/未最大化时的事件 [英] Event when a window gets maximized/un-maximized
问题描述
当您最大化或取消最大化表单时,是否会触发事件?
Is there an event that is fired when you maximize a Form or un-maximize it?
在你说 Resize
或 SizeChanged
之前:只有在 Size
实际改变时才会触发.如果您的窗口恰好与最大化窗口的大小相等,则它们不会触发.位置看起来是次佳选择,但这又像是在赌巧合.
Before you say Resize
or SizeChanged
: Those get only fired if the Size
actually changes. If your window happens to be equal in size to the maximized window, they do not fire. Location looks like the next best bet, but that again feels like gambling on a coincidence.
推荐答案
您可以通过覆盖 WndProc 来实现:
You can do this by overriding WndProc:
protected override void WndProc( ref Message m )
{
if( m.Msg == 0x0112 ) // WM_SYSCOMMAND
{
// Check your window state here
if (m.WParam == new IntPtr( 0xF030 ) ) // Maximize event - SC_MAXIMIZE from Winuser.h
{
// THe window is being maximized
}
}
base.WndProc(ref m);
}
这应该处理任何窗口上的事件.SC_RESTORE
是 0xF120
,SC_MINIMIZE
是 0XF020
,如果你也需要这些常量的话.
This should handle the event on any window. SC_RESTORE
is 0xF120
, and SC_MINIMIZE
is 0XF020
, if you need those constants, too.
这篇关于窗口最大化/未最大化时的事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!