怎样在用户关闭窗体时控制窗体不关闭?
当然不是指加按钮控制的方法,而是用户点窗体右上角的小红叉时,怎么控制呢?

解决方案 »

  1.   

    使用Form.Closing Event  private void Form1_Closing(object sender, System.ComponentModel.CancelEventArgs e)
    {
       // Determine if text has changed in the textbox by comparing to original text.
       if (textBox1.Text != strMyOriginalText)
       {
          // Display a MsgBox asking the user to save changes or abort.
          if(MessageBox.Show("Do you want to save changes to your text?", "My Application",
             MessageBoxButtons.YesNo) ==  DialogResult.Yes)
          {
             // Cancel the Closing event from closing the form.
             e.Cancel = true;
             // Call method to save file...
          }
       }
    }
      

  2.   

    Form1_Closing(object sender, System.ComponentModel.CancelEventArgs e)
    {
    e.Cancel =true;
    }
      

  3.   

    多谢大家了。我原来不知道这个:e.Cancel = true;