关闭消息框仅在更改文本时显示

时间:2019-02-15 13:33:23

标签: vba vb.net

所以我不相信下面的代码,因为它是由另一个用户提供给我的,并且不要误会我的意思,它虽然很好,但是现在我只希望消息框在文本框中的文本更改时显示,如果所有文本框均为空,仅在单击X时关闭应用程序。

感谢您的帮助!

'Creates _handle as boolean
Private _handle As Boolean = True

Private Sub MainWindow_Closing(sender As Object, e As CancelEventArgs) Handles Me.Closing

    'Creates a messagebox to ask if the user wants to exit the application or no. If yes application closes, if no then application stays open
    If _handle = True Then
        e.Cancel = True

        Dim result = MessageBox.Show("Are you sure you want to exit?", "Exit", MessageBoxButton.YesNo, MessageBoxImage.Question)
        If (result = MessageBoxResult.Yes) Then
            _handle = False
            Environment.Exit(0)
        End If
    End If

End Sub

0 个答案:

没有答案