本文為機器翻譯文章。如需檢視英文版,請選取 [原文] 核取方塊。您也可以將滑鼠指標移到文字上,即可在快顯視窗顯示英文原文。
譯文
原文

CancelEventArgs 類別

 

提供可取消事件的資料。

命名空間:   System.ComponentModel
組件:  System (於 System.dll)

System.Object
  System.EventArgs
    System.ComponentModel.CancelEventArgs
      Microsoft.VisualBasic.ApplicationServices.StartupEventArgs
      System.ComponentModel.DoWorkEventArgs
      System.Configuration.SettingChangingEventArgs
      System.Drawing.Printing.PrintEventArgs
      System.IdentityModel.Services.ErrorEventArgs
      System.IdentityModel.Services.RedirectingToIdentityProviderEventArgs
      System.IdentityModel.Services.SecurityTokenReceivedEventArgs
      System.IdentityModel.Services.SecurityTokenValidatedEventArgs
      System.IdentityModel.Services.SessionSecurityTokenReceivedEventArgs
      System.Web.ModelBinding.ModelValidatingEventArgs
      System.Web.UI.WebControls.DetailsViewDeleteEventArgs
      System.Web.UI.WebControls.DetailsViewInsertEventArgs
      System.Web.UI.WebControls.DetailsViewModeEventArgs
      System.Web.UI.WebControls.DetailsViewPageEventArgs
      System.Web.UI.WebControls.DetailsViewUpdateEventArgs
      System.Web.UI.WebControls.EntityDataSourceChangingEventArgs
      System.Web.UI.WebControls.EntityDataSourceContextDisposingEventArgs
      System.Web.UI.WebControls.EntityDataSourceSelectingEventArgs
      System.Web.UI.WebControls.FormViewDeleteEventArgs
      System.Web.UI.WebControls.FormViewInsertEventArgs
      System.Web.UI.WebControls.FormViewModeEventArgs
      System.Web.UI.WebControls.FormViewPageEventArgs
      System.Web.UI.WebControls.FormViewUpdateEventArgs
      System.Web.UI.WebControls.GridViewCancelEditEventArgs
      System.Web.UI.WebControls.GridViewDeleteEventArgs
      System.Web.UI.WebControls.GridViewEditEventArgs
      System.Web.UI.WebControls.GridViewPageEventArgs
      System.Web.UI.WebControls.GridViewSelectEventArgs
      System.Web.UI.WebControls.GridViewSortEventArgs
      System.Web.UI.WebControls.GridViewUpdateEventArgs
      System.Web.UI.WebControls.LinqDataSourceDeleteEventArgs
      System.Web.UI.WebControls.LinqDataSourceDisposeEventArgs
      System.Web.UI.WebControls.LinqDataSourceInsertEventArgs
      System.Web.UI.WebControls.LinqDataSourceSelectEventArgs
      System.Web.UI.WebControls.LinqDataSourceUpdateEventArgs
      System.Web.UI.WebControls.ListViewCancelEventArgs
      System.Web.UI.WebControls.ListViewDeleteEventArgs
      System.Web.UI.WebControls.ListViewEditEventArgs
      System.Web.UI.WebControls.ListViewInsertEventArgs
      System.Web.UI.WebControls.ListViewSelectEventArgs
      System.Web.UI.WebControls.ListViewSortEventArgs
      System.Web.UI.WebControls.ListViewUpdateEventArgs
      System.Web.UI.WebControls.ObjectDataSourceDisposingEventArgs
      System.Web.UI.WebControls.ObjectDataSourceFilteringEventArgs
      System.Web.UI.WebControls.ObjectDataSourceMethodEventArgs
      System.Web.UI.WebControls.SqlDataSourceCommandEventArgs
      System.Web.UI.WebControls.SqlDataSourceFilteringEventArgs
      System.Web.UI.WebControls.WebParts.WebPartCancelEventArgs
      System.Web.UI.WebControls.WebParts.WebPartConnectionsCancelEventArgs
      System.Web.UI.WebControls.WebParts.WebPartDisplayModeCancelEventArgs
      System.Windows.Controls.InkCanvasSelectionChangingEventArgs
      System.Windows.Controls.InkCanvasSelectionEditingEventArgs
      System.Windows.Controls.InkCanvasStrokeErasingEventArgs
      System.Windows.Forms.BindingCompleteEventArgs
      System.Windows.Forms.ColumnReorderedEventArgs
      System.Windows.Forms.ColumnWidthChangingEventArgs
      System.Windows.Forms.DataGridViewCellCancelEventArgs
      System.Windows.Forms.DataGridViewCellValidatingEventArgs
      System.Windows.Forms.DataGridViewRowCancelEventArgs
      System.Windows.Forms.DpiChangedEventArgs
      System.Windows.Forms.FormClosingEventArgs
      System.Windows.Forms.InputLanguageChangingEventArgs
      System.Windows.Forms.PopupEventArgs
      System.Windows.Forms.SplitterCancelEventArgs
      System.Windows.Forms.TabControlCancelEventArgs
      System.Windows.Forms.ToolStripDropDownClosingEventArgs
      System.Windows.Forms.TreeViewCancelEventArgs
      System.Windows.Forms.WebBrowserNavigatingEventArgs
      System.Windows.Navigation.NavigatingCancelEventArgs
      System.Windows.SessionEndingCancelEventArgs

[HostProtectionAttribute(SecurityAction.LinkDemand, SharedState = true)]
public class CancelEventArgs : EventArgs

名稱描述
System_CAPS_pubmethodCancelEventArgs()

初始化的新執行個體 CancelEventArgs 類別 Cancel 屬性設定為 false

System_CAPS_pubmethodCancelEventArgs(Boolean)

初始化的新執行個體 CancelEventArgs 類別 Cancel 屬性設定為指定的值。

名稱描述
System_CAPS_pubpropertyCancel

取得或設定值,指出是否應該取消事件。

名稱描述
System_CAPS_pubmethodEquals(Object)

判斷指定的物件是否等於目前的物件。(繼承自 Object。)

System_CAPS_protmethodFinalize()

允許物件在記憶體回收進行回收之前,嘗試釋放資源並執行其他清除作業。 (繼承自 Object。)

System_CAPS_pubmethodGetHashCode()

做為預設雜湊函式。(繼承自 Object。)

System_CAPS_pubmethodGetType()

取得目前執行個體的 Type(繼承自 Object。)

System_CAPS_protmethodMemberwiseClone()

建立目前 Object 的淺層複製。(繼承自 Object。)

System_CAPS_pubmethodToString()

傳回代表目前物件的字串。(繼承自 Object。)

A cancelable event is raised by a component when it is about to perform an action that can be canceled, such as the E:System.Windows.Forms.Form.Closing event of a T:System.Windows.Forms.Form.

System_CAPS_note注意

The E:System.Windows.Forms.Form.Closing event is deprecated and has been replaced by E:System.Windows.Forms.Form.FormClosing. It is offered as an example here only to illustrate the usage of T:System.ComponentModel.CancelEventArgs.

CancelEventArgs provides the Cancel property to indicate whether the event should be canceled.

The following example uses T:System.ComponentModel.CancelEventArgs and a T:System.ComponentModel.CancelEventHandler to handle the E:System.Windows.Forms.Form.Closing event of a T:System.Windows.Forms.Form. This code assumes that you have created a T:System.Windows.Forms.Form with a class-level T:System.Boolean variable named isDataSaved. It also assumes that you have added a statement to invoke the OtherInitialize method from the form's E:System.Windows.Forms.Form.Load method or the constructor (after the call to InitializeComponent).

// 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.");
       }
    }

通用 Windows 平台
自 8 起供應
.NET Framework
自 1.1 起供應
可攜式類別庫
提供支援︰ 可攜式 .NET 平台
Silverlight
自 3.0 起供應
Windows Phone Silverlight
自 7.0 起供應
Windows Phone
自 8.1 起供應

此類型的任何 public static (在 Visual Basic 中 共用 在 Visual Basic 中) 成員皆為安全執行緒。不保證任何執行個體成員為安全執行緒。

回到頁首
顯示: