登录表单上的退出按钮

时间:2013-11-06 00:09:34

标签: vb.net

这是否足以代表表单上的退出按钮?

这是我的代码:

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

1 个答案:

答案 0 :(得分:2)

是的,这已经足够了,但是:

  1. 您应该使用Me.Close()代替Me.Dispose()

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