0

对于我的表单上的退出按钮,这是足够的代码吗?

这是我的代码:

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Dim response As MsgBoxResult
        response = MsgBox("Do you want to close form?", MsgBoxStyle.Question + MsgBoxStyle.YesNo, "Confirm")
        If response = MsgBoxResult.Yes Then
            Me.Dispose()
        ElseIf response = MsgBoxResult.No Then 'Button to exit the program completely 
            Exit Sub
        End If
End Sub
4

1 回答 1

2

是的,这就足够了,但是:

  1. 您应该使用Me.Close()而不是Me.Dispose().

  2. 如果这是您的应用程序的完全退出并且您有任何非托管资源(例如数据库连接、打开的文件、COM 对象等)。你应该关闭它们/清理它们。

于 2013-11-06T00:17:32.907 回答