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 。 此報告可協助您瞭解事件發生的時間,並可協助您進行偵錯。 若要報告多個事件或經常發生的事件,請考慮將 取代 ShowConsole.WriteLine 或將訊息附加至多行 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) ,或透過程式設計方式,透過呼叫 類別 ExitApplication 或 類別中等 CloseForm 方法。

如果表單有任何子表單或擁有的表單, FormClosing 也會針對每個表單引發事件。 如果任一表單取消事件,則不會關閉任何表單。 因此,對應的 FormClosed 事件不會傳送至任何表單。

類別 FormClosingEventArgs 會提供這個事件的資料。 兩個重要成員是 CancelCloseReason 屬性。 您可以將 屬性設定 Cancel 為 true 來取消事件。 屬性 CloseReason 提供關閉表單的原因。

建構函式

FormClosingEventArgs(CloseReason, Boolean)

初始化 FormClosingEventArgs 類別的新執行個體。

屬性

Cancel

取得或設定值,這個值表示是否應該取消事件。

(繼承來源 CancelEventArgs)
CloseReason

取得值,表示關閉表單的原因。

方法

Equals(Object)

判斷指定的物件是否等於目前的物件。

(繼承來源 Object)
GetHashCode()

做為預設雜湊函式。

(繼承來源 Object)
GetType()

取得目前執行個體的 Type

(繼承來源 Object)
MemberwiseClone()

建立目前 Object 的淺層複製。

(繼承來源 Object)
ToString()

傳回代表目前物件的字串。

(繼承來源 Object)

適用於

另請參閱