CancelEventArgs クラス
重要
一部の情報は、リリース前に大きく変更される可能性があるプレリリースされた製品に関するものです。 Microsoft は、ここに記載されている情報について、明示または黙示を問わず、一切保証しません。
キャンセルできるイベントのデータを提供します。
public ref class CancelEventArgs : EventArgs
public class CancelEventArgs : EventArgs
type CancelEventArgs = class
inherit EventArgs
Public Class CancelEventArgs
Inherits EventArgs
- 継承
- 派生
次の例では、 と をCancelEventHandler使用CancelEventArgsして のイベントをFormClosing処理します。 このコードでは、 という名前isDataSaved
のクラス レベルBooleanの変数を使用して をForm作成していることを前提としています。 また、(の呼び出しの後に) フォームの Load メソッドまたはコンストラクターからメソッドを呼びInitializeComponent
出すOtherInitialize
ステートメントを追加したと想定しています。
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
キャンセル可能なイベントは、 の イベントなどClosingForm、取り消し可能なアクションを実行しようとしているコンポーネントによって発生します。
注意
イベントは Closing 非推奨であり、 に FormClosing置き換えられました。 の使用方法 CancelEventArgsを示すためだけに、ここでの例として提供されています。
CancelEventArgs は、イベントを Cancel 取り消す必要があるかどうかを示す プロパティを提供します。
Cancel |
CancelEventArgs プロパティを |
Cancel |
CancelEventArgs プロパティを特定の値に設定して、Cancel クラスの新しいインスタンスを初期化します。 |
Cancel |
イベントをキャンセルするかどうかを示す値を取得または設定します。 |
Equals(Object) |
指定されたオブジェクトが現在のオブジェクトと等しいかどうかを判断します。 (継承元 Object) |
Get |
既定のハッシュ関数として機能します。 (継承元 Object) |
Get |
現在のインスタンスの Type を取得します。 (継承元 Object) |
Memberwise |
現在の Object の簡易コピーを作成します。 (継承元 Object) |
To |
現在のオブジェクトを表す文字列を返します。 (継承元 Object) |
製品 | バージョン |
---|---|
.NET | Core 1.0, Core 1.1, Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9 |
.NET Framework | 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1 |
.NET Standard | 2.0, 2.1 |
UWP | 10.0 |
.NET に関するフィードバック
.NET はオープンソース プロジェクトです。 フィードバックを提供するにはリンクを選択します。