2

我想在用户单击 x 按钮后但在程序退出之前执行一些操作。

是否可以 ?如果是,那我该怎么做?

4

3 回答 3

6

查看表单关闭事件

代码示例 VB.Net:

Private Sub Form1_FormClosing(ByVal sender As System.Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles MyBase.FormClosing

End Sub

和 c#

private void Form1_FormClosing(System.Object sender, System.Windows.Forms.FormClosingEventArgs e)
{
}
于 2012-11-22T10:43:15.450 回答
0

查看 FormOnClosed 表单事件处理程序的事件示例 c# CODE private void formname_FormClosed(object sender, FormClosedEventArgs e) { //urcode }

于 2012-11-22T10:43:27.793 回答
0

您可以处理事件 FormClosing。这里记录了:http: //msdn.microsoft.com/en-us/library/system.windows.forms.form.formclosing.aspx

代码示例:

 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" );
}
于 2012-11-22T10:45:01.717 回答