FormClosingEventArgs クラス

定義

FormClosing イベントのデータを提供します。

public ref class FormClosingEventArgs : System::ComponentModel::CancelEventArgs
public class FormClosingEventArgs : System.ComponentModel.CancelEventArgs
type FormClosingEventArgs = class
    inherit CancelEventArgs
Public Class FormClosingEventArgs
Inherits CancelEventArgs
継承
FormClosingEventArgs

次のコード例では、この型の使用方法を示します。 この例では、イベント ハンドラーがイベントの FormClosing 発生を報告します。 このレポートは、イベントが発生したタイミングを知るのに役立ち、デバッグに役立ちます。 複数のイベントまたは頻繁に発生するイベントを報告するには、 を Console.WriteLine に置き換えるかShow、複数行TextBoxにメッセージを追加することを検討してください。

コード例を実行するには、 という名前Form1の型Formのインスタンスを含むプロジェクトに貼り付けます。 次に、イベント ハンドラーが イベントに関連付けられていることを確認します FormClosing

private void Form1_FormClosing(Object sender, FormClosingEventArgs e) {

System.Text.StringBuilder messageBoxCS = new System.Text.StringBuilder();
messageBoxCS.AppendFormat("{0} = {1}", "CloseReason", e.CloseReason );
messageBoxCS.AppendLine();
messageBoxCS.AppendFormat("{0} = {1}", "Cancel", e.Cancel );
messageBoxCS.AppendLine();
MessageBox.Show(messageBoxCS.ToString(), "FormClosing Event" );
}
Private Sub Form1_FormClosing(sender as Object, e as FormClosingEventArgs) _ 
     Handles Form1.FormClosing

    Dim messageBoxVB as New System.Text.StringBuilder()
    messageBoxVB.AppendFormat("{0} = {1}", "CloseReason", e.CloseReason)
    messageBoxVB.AppendLine()
    messageBoxVB.AppendFormat("{0} = {1}", "Cancel", e.Cancel)
    messageBoxVB.AppendLine()
    MessageBox.Show(messageBoxVB.ToString(),"FormClosing Event")

End Sub

注釈

イベントはFormClosing、ユーザーが、ユーザー インターフェイス (UI) を介して、またはプログラムによって、 クラス内や クラスExit内などのCloseFormメソッドの呼び出しを通じて、フォームが閉じられる直前にApplication発生します。

フォームに子フォームまたは所有フォームがある場合は、 FormClosing それぞれに対してイベントも発生します。 いずれかのフォームでイベントが取り消された場合、どのフォームも閉じられています。 そのため、対応する FormClosed イベントはいずれのフォームにも送信されません。

クラスは FormClosingEventArgs 、このイベントのデータを提供します。 2 つの重要なメンバーは、 Cancel プロパティと CloseReason プロパティです。 イベントは、 プロパティを true に Cancel 設定することで取り消すことができます。 プロパティは CloseReason 、フォームが閉じられている理由を示します。

コンストラクター

FormClosingEventArgs(CloseReason, Boolean)

FormClosingEventArgs クラスの新しいインスタンスを初期化します。

プロパティ

Cancel

イベントをキャンセルするかどうかを示す値を取得または設定します。

(継承元 CancelEventArgs)
CloseReason

フォームが閉じられようとしている理由を示す値を取得します。

メソッド

Equals(Object)

指定されたオブジェクトが現在のオブジェクトと等しいかどうかを判断します。

(継承元 Object)
GetHashCode()

既定のハッシュ関数として機能します。

(継承元 Object)
GetType()

現在のインスタンスの Type を取得します。

(継承元 Object)
MemberwiseClone()

現在の Object の簡易コピーを作成します。

(継承元 Object)
ToString()

現在のオブジェクトを表す文字列を返します。

(継承元 Object)

適用対象

こちらもご覧ください