窗口最大化/未最大化时的事件 [英] Event when a window gets maximized/un-maximized

查看:43
本文介绍了窗口最大化/未最大化时的事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当您最大化或取消最大化表单时,是否会触发事件?

Is there an event that is fired when you maximize a Form or un-maximize it?

在你说 ResizeSizeChanged 之前:只有在 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_RESTORE0xF120SC_MINIMIZE0XF020,如果你也需要这些常量的话.

This should handle the event on any window. SC_RESTORE is 0xF120, and SC_MINIMIZE is 0XF020, if you need those constants, too.

这篇关于窗口最大化/未最大化时的事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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