[英]Visual Basic MsgBox vbYesNo Doesn't accept when the 'No' button is clicked
我的 VB.NET 表單程序中有一個 MsgBox,附加了一個 vbYesNo 參數。 每當消息框顯示時,我都會看到是和否按鈕,但是無論我單擊哪個按鈕,我總是得到相同的結果。
這是我的代碼:
MsgBox("Here's 2 options...", vbYesNo)
If vbYes Then
MsgBox("You clicked yes")
Else
MsgBox("You clicked no")
End If
我也嘗試過與上面相同的 If 語句:
If vbYes Then
MsgBox("You clicked yes")
ElseIf vbNo Then
MsgBox("You clicked no")
End If
當我在 Messagee Box 上單擊是或否時,我總是得到以下內容:
If vbYes Then
MsgBox("You clicked yes")
我對 Visual Basic forms 比較陌生,所以如果這是一個簡單的新手錯誤,我很抱歉。 我希望這些信息足以讓 go 上。
謝謝您的幫助。
嘗試以下操作:
選項 1 :
If MessageBox.Show("Here's 2 options", "Select Option", MessageBoxButtons.YesNo, MessageBoxIcon.Question) = DialogResult.Yes Then
MessageBox.Show("You clicked yes", "Result")
Else
MessageBox.Show("You clicked no", "Result")
End If
選項 2 :
If MsgBox("Here's 2 options", vbYesNo, "Select option") = vbYes Then
MsgBox("You clicked yes", vbOKOnly, "Result")
Else
MsgBox("You clicked no", vbOKOnly, "Result")
End If
您的問題是您沒有捕獲 MsgBox 返回的值,您應該嘗試以下操作:
Dim a As MsgBoxResult = MsgBox("Here's 2 options...", vbYesNo)
If a = vbYes Then
MsgBox("You clicked yes")
Else
MsgBox("You clicked no")
End If
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.