How to disable the minimize button in C#?

后端 未结 8 827
花落未央
花落未央 2020-12-06 13:33

In my application I need to temporarily gray out the minimize button of the main form. Any ideas how this can be achieved? I don\'t mind doing p/invokes to Win32 dlls.

相关标签:
8条回答
  • 2020-12-06 13:45

    Just do MinimizeBox = false; in your form's code.

    0 讨论(0)
  • 2020-12-06 13:49

    You can also implement handle to the Minimize event to cancel the command

    0 讨论(0)
  • 2020-12-06 13:54

    Coincoin's answer is correct. MinimizeBox is also available as a property in the designer properties window.

    @Kevin: While I appreciate the sentiment, that's not always a valid answer. If the application displays a modal dialog box by creating a new instance of a Form and then calling .ShowDialog() on it, you don't want the user to minimize that Form, because then all input on the main UI thread is blocked until that Form's modal status is satisfied. The user could potentially click on the main form and just get the "ding ding ding" unresponsive sound from Windows and not know what to do.

    0 讨论(0)
  • 2020-12-06 13:56

    Put this code in your form's Resize event:

    if (this.WindowState == FormWindowState.Minimized)
    {
        this.WindowState = FormWindowState.Normal;
    }
    

    This will make your form un-minimizable (DISCLAIMER: I do not advocate altering the standard behavior of windows in this way).

    0 讨论(0)
  • 2020-12-06 13:58
    form.MinimizeBox = false;
    

    or if in the form scope

    MinimizeBox = false;
    
    0 讨论(0)
  • 2020-12-06 13:58

    Don't. Don't mess with my windows. They are mine, not yours. It is my computer and if I want to minimize, I should be able to. I can't think of, and have never been given, a good reason for doing this.

    0 讨论(0)
提交回复
热议问题