【发布时间】:2014-08-10 13:05:15
【问题描述】:
我想知道我可以在下面第一个 if 语句的第二部分输入什么代码,以便在单击取消按钮时保持表单处于活动状态。
Private Sub ExitToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles ExitToolStripMenuItem.Click
'Message prompt to ask if the user really want to exit
MsgBox("Are you sure you want to exit?", MsgBoxStyle.OkCancel, "MDCS")
If MsgBoxResult.Ok Then
If Application.OpenForms().OfType(Of Find_Client).Any Or Application.OpenForms().OfType(Of Form_items).Any Then
MsgBox("Close all opened windows before the main", MsgBoxStyle.OkOnly, "MDCS")
Else
' Call sub that close the program
Me.Close()
Dim items As New Form_items, clients As New Find_Client
items.Close()
clients.Close()
'Stop Stopwatch
Timer1.Stop()
Me.StopWatch.Stop()
'Mark Stopwatch value
intTimerValues = Val(Timer_Label.Text)
End If
Else
???
End If
End Sub
【问题讨论】:
-
你是怎么调用函数的?
-
exit_program。我在退出按钮中调用它来关闭应用程序。当单击取消按钮时,应该有可能退出程序。
-
您没有向我们展示任何实际退出程序的代码。
-
将代码放入表单的
Closing事件中,如果您的表单不应关闭,请通过 ClosingEventArgs 取消它:e.Cancel = True。 -
他说代码应该放在
Form_Closing事件中。