Event when a window gets maximized/un-maximized

前端 未结 10 880
失恋的感觉
失恋的感觉 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:16

    Suprising that no one mentioned the inbuilt .NET method.

    This way you don't need to override the Window Message Processing handler.

    It even captures maximize/restore events caused by double-clicking the window titlebar, which the WndProc method does not.

    Copy this in and link it to the "Resize" event handler on the form.

        FormWindowState LastWindowState = FormWindowState.Minimized;
        private void Form1_Resize(object sender, EventArgs e) {
    
            // When window state changes
            if (WindowState != LastWindowState) {
                LastWindowState = WindowState;
    
    
                if (WindowState == FormWindowState.Maximized) {
    
                    // Maximized!
                }
                if (WindowState == FormWindowState.Normal) {
    
                    // Restored!
                }
            }
    
        }
    

提交回复
热议问题