VB2010Express MessageBox多次出现

VB2010Express MessageBox appears multiple times

这里是使用 VB2010 Express 的初学者 - 使用 MessageBox.show IF/ELSEIF 语句但我的按钮必须按几次,第一次 btn 一次,第二次两次,第三次三次,然后才实际出现消息对话框显示。我不知道我的 Dim 语句如何与此相关联。昏暗的结果为...

    Private Sub btnMessage_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnMessage.Click
        Dim Result As 
        If MessageBox.Show("Click something.", "Title", MessageBoxButtons.AbortRetryIgnore, MessageBoxIcon.Question) = Windows.Forms.DialogResult.Abort Then
            MessageBox.Show("Aborted")
        ElseIf MessageBox.Show("Click something", "Title", MessageBoxButtons.AbortRetryIgnore, MessageBoxIcon.Question) = Windows.Forms.DialogResult.Retry Then
            MessageBox.Show("Retrying.")
        ElseIf MessageBox.Show("Click something", " Title", MessageBoxButtons.AbortRetryIgnore, MessageBoxIcon.Question) = Windows.Forms.DialogResult.Ignore Then
            MessageBox.Show("Ignoring.")
        End If
    End Sub
End Class

您错过了一些非常重要非常基本的编程概念。这里不是教你那些基础知识的地方 - 那是大学的目的。

足以说明您有三个完全独立的消息框,因此它们可以出现三次。

解决方法是(正确)使用变量:

Dim result
result = MessageBox.Show("Click something.", "Title", MessageBoxButtons.AbortRetryIgnore, MessageBoxIcon.Question)
'store the chosen answer in the "result" variable, then use it to check the result

If result = Windows.Forms.DialogResult.Abort Then
    MessageBox.Show ("Aborted")
ElseIf result = Windows.Forms.DialogResult.Retry Then
    MessageBox.Show ("Retrying.")
ElseIf result = Windows.Forms.DialogResult.Ignore Then
    MessageBox.Show ("Ignoring.")
End If