Event when a window gets maximized/un-maximized

前端 未结 10 873
失恋的感觉
失恋的感觉 2020-11-27 05:48

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

Before you say Resize or SizeChanged: Those get only fired if t

10条回答
  •  抹茶落季
    2020-11-27 06:29

    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);
    }
    

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

提交回复
热议问题