Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/vb.net/17.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Vb.net 登录表单上的退出按钮_Vb.net - Fatal编程技术网

Vb.net 登录表单上的退出按钮

Vb.net 登录表单上的退出按钮,vb.net,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 + MsgBoxS

对于我的表单上的退出按钮,这是否足够

这是我的代码:

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

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

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

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


  • 为什么不是Me.Close而不是Me.Dispose()?如果打开了数据库连接,应该将其关闭。如果您有COM对象,您应该处理它们。您还应该使用MessageBox.Show()而不是旧的MsgBox()。在使用MsgBox()时,我看到表单和消息发生了奇怪的事情。