Disabling Minimize & Maximize On WinForm?

前端 未结 7 1739
逝去的感伤
逝去的感伤 2020-12-02 09:43

WinForms have those three boxes in the upper right hand corner that minimize, maximize, and close the form. What I want to be able to do is to remove the minimize and maxim

相关标签:
7条回答
  • 2020-12-02 09:57

    Right Click the form you want to hide them on, choose Controls -> Properties.

    In Properties, set

    • Control Box -> False
    • Minimize Box -> False
    • Maximize Box -> False

    You'll do this in the designer.

    0 讨论(0)
  • 2020-12-02 10:02
    public Form1()
    {
    InitializeComponent();
    //this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle;
    this.MaximizeBox = false;
    this.MinimizeBox = false;
    }
    
    0 讨论(0)
  • 2020-12-02 10:03

    Bind a handler to the FormClosing event, then set e.Cancel = true, and set the form this.WindowState = FormWindowState.Minimized.

    If you want to ever actually close the form, make a class-wide boolean _close and, in your handler, set e.Cancel to !_close, so that whenever the user clicks the X on the window, it doesn't close, but you can still close it (without just killing it) with close = true; this.Close();

    (And just to make my answer complete) set MaximizeBox and MinimizeBox form properties to False.

    0 讨论(0)
  • 2020-12-02 10:10

    you can simply disable maximize inside form constructor.

     public Form1(){
         InitializeComponent();
         MaximizeBox = false;
     }
    

    to minimize when closing.

    private void Form1_FormClosing(Object sender, FormClosingEventArgs e) {
        e.Cancel = true;
        WindowState = FormWindowState.Minimized;
    }
    
    0 讨论(0)
  • 2020-12-02 10:12

    Set MaximizeBox and MinimizeBox form properties to False

    0 讨论(0)
  • 2020-12-02 10:17

    The Form has two properties called MinimizeBox and MaximizeBox, set both of them to false.

    To stop the form closing, handle the FormClosing event, and set e.Cancel = true; in there and after that, set WindowState = FormWindowState.Minimized;, to minimize the form.

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