Disabling the Close-Button temporarily

后端 未结 7 1122
后悔当初
后悔当初 2020-12-31 14:45

I need to disable just the close button (minimize and maximize should be allowed) temporarily.

Every solution I\'ve tried disables all the buttons

7条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-12-31 14:55

    isprocessing = true;
    form.FormClosing += new FormClosingEventHandler(form_cancel); 
    private void form_cancel(object sender, FormClosingEventArgs e)
    {
       if (isprocessing)
       {
          e.Cancel = true;  //disables the form close when processing is true
       }
       else
       {
          e.Cancel = false; //enables it later when processing is set to false at some point 
        }
    }
    

    This worked for me

提交回复
热议问题