CancelEventArgsとは? わかりやすく解説

CancelEventArgs クラス

キャンセルできるイベントのデータを提供します。

名前空間: System.ComponentModel
アセンブリ: System (system.dll 内)
構文構文

Public Class CancelEventArgs
    Inherits EventArgs
Dim instance As CancelEventArgs
public class CancelEventArgs : EventArgs
public ref class CancelEventArgs : public
 EventArgs
public class CancelEventArgs extends EventArgs
public class CancelEventArgs extends
 EventArgs
解説解説
使用例使用例

CancelEventArgs と CancelEventHandler を使用して、Form の Closing イベントを処理する例を次に示します。このコードは、クラス レベルの Boolean 変数 isDataSaved を持つ Form が作成されていることを前提にしています。また、OtherInitialize メソッドをフォームの Load メソッドまたはコンストラクタから (InitializeComponent の呼び出しの後で) 起動するためのステートメントが追加されていることも前提にしています。

' 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 'OtherInitialize

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 'Form1_Closing
// 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.");
       }
    }
 
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." );
      }
   }
// Calls this method from the InitializeComponent() method of your form
private void OtherInitialize()
{
    this.add_Closing(new CancelEventHandler(this.Form1_Cancel));
    this.myDataIsSaved = (boolean)new System.Boolean();
    this.myDataIsSaved = true;
} //OtherInitialize

protected void Form1_Cancel(Object sender,
 CancelEventArgs e)
{
    if (!(myDataIsSaved)) {
        e.set_Cancel(true);
        MessageBox.Show("You must save first.");
    }
    else {
        e.set_Cancel(false);
        MessageBox.Show("Goodbye.");
    }
} //Form1_Cancel
継承階層継承階層
System.Object
   System.EventArgs
    System.ComponentModel.CancelEventArgs
       派生クラス
スレッド セーフスレッド セーフ
この型の public static (Visual Basic では Shared) メンバはすべて、スレッド セーフです。インスタンス メンバの場合は、スレッド セーフであるとは限りません。
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照
関連項目
CancelEventArgs メンバ
System.ComponentModel 名前空間
CancelEventHandler

CancelEventArgs コンストラクタ ()


CancelEventArgs コンストラクタ


CancelEventArgs コンストラクタ (Boolean)


CancelEventArgs プロパティ


CancelEventArgs メソッド


CancelEventArgs メンバ

キャンセルできるイベントのデータを提供します。

CancelEventArgs データ型で公開されるメンバを以下の表に示します。


パブリック コンストラクタパブリック コンストラクタ
パブリック プロパティパブリック プロパティ
パブリック メソッドパブリック メソッド
プロテクト メソッドプロテクト メソッド
参照参照

関連項目

CancelEventArgs クラス
System.ComponentModel 名前空間
CancelEventHandler



英和和英テキスト翻訳

英語⇒日本語日本語⇒英語

辞書ショートカット

すべての辞書の索引

「CancelEventArgs」の関連用語

CancelEventArgsのお隣キーワード
検索ランキング

   

英語⇒日本語
日本語⇒英語
   



CancelEventArgsのページの著作権

   
日本マイクロソフト株式会社日本マイクロソフト株式会社
© 2026 Microsoft.All rights reserved.

©2026 GRAS Group, Inc.RSS