这是否足以代表表单上的退出按钮?
这是我的代码:
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
答案 0 :(得分:2)
是的,这已经足够了,但是:
您应该使用Me.Close()
代替Me.Dispose()
。
如果这是完全从您的应用程序退出并且您有任何非托管资源(例如数据库连接,文件打开,COM对象等)。你应该关闭它们/清理它们。