CancelEventArgs 类  
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
为可取消的事件提供数据。
public ref class CancelEventArgs : EventArgspublic class CancelEventArgs : EventArgstype CancelEventArgs = class
    inherit EventArgsPublic Class CancelEventArgs
Inherits EventArgs- 继承
- 派生
示例
以下示例使用 CancelEventArgs 和 CancelEventHandler 来处理 Closing 的 Form事件。 此代码假定你已使用名为 isDataSaved的类级Boolean变量创建了 Form 。 它还假定你已添加一个 语句,用于OtherInitialize在调用 InitializeComponent) 后从窗体的 Load 方法或构造函数 (调用方法。
private:
   // Call this method from the InitializeComponent() method of your form
   void OtherInitialize()
   {
      this->Closing += gcnew CancelEventHandler( this, &Form1::Form1_Cancel );
      this->myDataIsSaved = true;
   }
   void Form1_Cancel( Object^ /*sender*/, CancelEventArgs^ e )
   {
      if ( !myDataIsSaved )
      {
         e->Cancel = true;
         MessageBox::Show( "You must save first." );
      }
      else
      {
         e->Cancel = false;
         MessageBox::Show( "Goodbye." );
      }
   }
// Call this method from the constructor of your form
    private void OtherInitialize() {
       this.Closing += new CancelEventHandler(this.Form1_Closing);
       // Exchange commented line and note the difference.
       this.isDataSaved = true;
       //this.isDataSaved = false;
    }
    private void Form1_Closing(Object sender, CancelEventArgs e) {
       if (!isDataSaved) {
          e.Cancel = true;
          MessageBox.Show("You must save first.");
       }
       else {
          e.Cancel = false;
          MessageBox.Show("Goodbye.");
       }
    }
' Call this method from the Load method of your form.
Private Sub OtherInitialize()
    ' Exchange commented line and note the difference.
    Me.isDataSaved = True
    'Me.isDataSaved = False
End Sub
Private Sub Form1_Closing(sender As Object, e As _
   System.ComponentModel.CancelEventArgs) Handles MyBase.Closing
    If Not isDataSaved Then
        e.Cancel = True
        MessageBox.Show("You must save first.")
    Else
        e.Cancel = False
        MessageBox.Show("Goodbye.")
    End If
End Sub
注解
组件在即将执行可取消的操作(例如 Closing 的 事件)时引发可取消事件 Form。
注意
事件 Closing 已弃用,已替换为 FormClosing。 此处作为示例提供,只是为了说明 的 CancelEventArgs用法。
CancelEventArgs Cancel提供 属性以指示是否应取消事件。
构造函数
| CancelEventArgs() | 初始化 CancelEventArgs 类的新实例,其 Cancel 属性设置为  | 
| CancelEventArgs(Boolean) | 初始化 CancelEventArgs 类的新实例,其 Cancel 属性设置为给定值。 | 
属性
| Cancel | 获取或设置指示是否应取消事件的值。 | 
方法
| Equals(Object) | 确定指定对象是否等于当前对象。(继承自 Object) | 
| GetHashCode() | 作为默认哈希函数。(继承自 Object) | 
| GetType() | 获取当前实例的 Type。(继承自 Object) | 
| MemberwiseClone() | 创建当前 Object 的浅表副本。(继承自 Object) | 
| ToString() | 返回表示当前对象的字符串。(继承自 Object) |