CancelEventArgs クラス
定義
重要
一部の情報は、リリース前に大きく変更される可能性があるプレリリースされた製品に関するものです。 Microsoft は、ここに記載されている情報について、明示または黙示を問わず、一切保証しません。
キャンセルできるイベントのデータを提供します。
public ref class CancelEventArgs : EventArgs
public class CancelEventArgs : EventArgs
type CancelEventArgs = class
inherit EventArgs
Public Class CancelEventArgs
Inherits EventArgs
- 継承
- 派生
例
次の例ではCancelEventArgs、.CancelEventHandler Closing Form このコードでは、クラス レベルBooleanの変数を名前isDataSaved
付きで作成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 イベントを取り消す必要があるかどうかを示すプロパティを提供します。
コンストラクター
CancelEventArgs() |
CancelEventArgs プロパティを |
CancelEventArgs(Boolean) |
CancelEventArgs プロパティを特定の値に設定して、Cancel クラスの新しいインスタンスを初期化します。 |
プロパティ
Cancel |
イベントをキャンセルするかどうかを示す値を取得または設定します。 |
メソッド
Equals(Object) |
指定されたオブジェクトが現在のオブジェクトと等しいかどうかを判断します。 (継承元 Object) |
GetHashCode() |
既定のハッシュ関数として機能します。 (継承元 Object) |
GetType() |
現在のインスタンスの Type を取得します。 (継承元 Object) |
MemberwiseClone() |
現在の Object の簡易コピーを作成します。 (継承元 Object) |
ToString() |
現在のオブジェクトを表す文字列を返します。 (継承元 Object) |