CancelEventArgs クラス
アセンブリ: System (system.dll 内)


キャンセルできるイベントは、Form の Closing イベントなど、キャンセル可能なアクションをコンポーネントが実行しようとしたときに発生します。
CancelEventArgs には、イベントをキャンセルするかどうかを示す Cancel プロパティがあります。
![]() |
---|
このクラスに適用される HostProtectionAttribute 属性の Resources プロパティの値は、SharedState です。HostProtectionAttribute は、デスクトップ アプリケーション (一般的には、アイコンをダブルクリック、コマンドを入力、またはブラウザに URL を入力して起動するアプリケーション) には影響しません。詳細については、HostProtectionAttribute クラスのトピックまたは「SQL Server プログラミングとホスト保護属性」を参照してください。 |

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



Windows 98, Windows 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


Weblioに収録されているすべての辞書からCancelEventArgs クラスを検索する場合は、下記のリンクをクリックしてください。

- CancelEventArgs クラスのページへのリンク