使用消息框确认程序关闭

Bin*_*323 3 vb.net

我有一个消息框,当我按下一个关闭按钮时会弹出一个消息框,上面写着“您确定要退出吗”但是当我单击“否”按钮或取消但程序以任何方式关闭时

这是我的代码:

'Close Button
Private Sub BtnClose_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnClose.Click

    Dim result = MessageBox.Show(" Are you sure you want to quit", "Are you sure?", MessageBoxButtons.YesNoCancel)
    Me.Close()

End Sub
Run Code Online (Sandbox Code Playgroud)

bil*_*nkc 5

您对 的价值无动于衷result。您需要检查该值并确定您是否调用了 Me.Close()。代码大约

If result = DialogResult.Yes Then
    Me.Close()
End If
Run Code Online (Sandbox Code Playgroud)