3

基本的に「終了してもよろしいですか」という閉じるボタンを押すとポップアップするメッセージボックスがありますが、いいえボタンをクリックするかキャンセルすると、プログラムはどのように閉じます

これは私のコードです:

'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
4

8 に答える 8

5

の値で何もしていませんresult。値を調べて、Me.Close() を呼び出すかどうかを判断する必要があります。おおよそのコード

If result = DialogResult.Yes Then
    Me.Close()
End If
于 2013-06-26T02:45:15.353 に答える
2

Me.Close()何が何であれ、あなたは発行しresultます。結果を確認しMe.Close()、ユーザーのクリックのみを実行Yes

于 2013-06-26T02:42:59.123 に答える
2
Private Sub btnClose_Click(sender As Object, e As EventArgs) Handles btnClose.Click
  If MsgBox("Are you sure you want to quit?", MsgBoxStyle.YesNo Or MsgBoxStyle.DefaultButton2, "Close application") = Windows.Forms.DialogResult.Yes Then
    Me.Close()
  End If
End Sub
于 2013-06-26T02:45:57.063 に答える
2

これをコピーします:

    Dim result = MessageBox.Show(" Are you sure you want to end the Application", "School Management System", MessageBoxButtons.YesNoCancel)
    If result = DialogResult.Yes Then
        Me.Close()
    End If
于 2016-08-16T16:34:37.807 に答える
1
 Dim result = MessageBox.Show(" Are you sure you want to quit", "System Reminder", MessageBoxButtons.YesNo)
    If result = DialogResult.Yes Then
        Me.Close()

    End If
于 2014-02-17T06:12:44.227 に答える