Event when a window gets maximized/un-maximized

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

    I'm a newbie here so comments not allowed, but this IS a comment to the clean answer by GeoTarget:

    The first line OUGHT to be slightly changed to nullable, to catch if the form is started Minimized:

    FormWindowState? LastWindowState = null;
    

    And a banal suggestion: Move the assignment of LastWindowState to after the "if"s, so the user can easily check not only what you go to, but also what it came from:

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

提交回复
热议问题