Search code examples
c#winformsminimize

Cancel A WinForm Minimize?


I have a winform with the minimizeMaximizeClose buttons disabled, but still if someone presses it in the task bar, it will minimize. I want to prevent this from happening.

How can I accomplish this?


Solution

  • You could probably catch them changing it in the SizeChanged event and check the WindowState, if its been set to Minimized then set it back Normal. Not the most elegant solution but should work.

    eg.

    private void myForm_SizeChanged(object sender, System.EventArgs e)
    {
       if (myForm.WindowState == FormWindowState.Minimized)
       {
           myForm.WindowState = FormWindowState.Normal;
       }
    }