简体   繁体   English

Visual Basic MsgBox vbYesNo 单击“否”按钮时不接受

[英]Visual Basic MsgBox vbYesNo Doesn't accept when the 'No' button is clicked

I have a MsgBox in my VB.NET Form's program with a vbYesNo parameter attached.我的 VB.NET 表单程序中有一个 MsgBox,附加了一个 vbYesNo 参数。 Whenever the messagebox shows, I see the yes and no buttons, however no matter which button I click, I always get the same result.每当消息框显示时,我都会看到是和否按钮,但是无论我单击哪个按钮,我总是得到相同的结果。

Here's my code:这是我的代码:

MsgBox("Here's 2 options...", vbYesNo)
If vbYes Then
    MsgBox("You clicked yes")
Else
    MsgBox("You clicked no")
End If

I've also tried the same as above where the If statement is:我也尝试过与上面相同的 If 语句:

If vbYes Then
    MsgBox("You clicked yes")
ElseIf vbNo Then
    MsgBox("You clicked no")
End If

When I click Yes, or No on the Messagee Box, I always get whatever's in:当我在 Messagee Box 上单击是或否时,我总是得到以下内容:

If vbYes Then
    MsgBox("You clicked yes")

I'm relatively new to Visual Basic forms so I'm sorry if this is a simple rookie mistake.我对 Visual Basic forms 比较陌生,所以如果这是一个简单的新手错误,我很抱歉。 I hope this info is enough to go on.我希望这些信息足以让 go 上。

Thanks for the help.谢谢您的帮助。

Try the following:尝试以下操作:

Option 1 :选项 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

Option 2 :选项 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

your issue is that you are not capturing the value returned by the MsgBox, you should try something like this:您的问题是您没有捕获 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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM