0

我想出了如何清除文本框,但是当我按下NoMessageBox 时它就会清除。我希望它清除用户是否选择Yes. 如果用户选择No,那么我什么也不想做。

    Private Sub BtnFah_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnFah.Click
        Try
            Dim intFah As Integer
            intFah = CInt(TxtBoxTemp.Text)
            intFah = (intFah * 9) / 5 - 32
            If MessageBox.Show(intFah.ToString & ControlChars.CrLf & "Would you like to start another temp conversion?", "Result", MessageBoxButtons.YesNo) Then
                TxtBoxTemp.Text = String.Empty
            End If
        Catch
            MessageBox.Show("Would you like to start another temp conversion?", "System Error", MessageBoxButtons.YesNo)

        End Try
    End Sub
4

4 回答 4

2

你需要比较DialogResult

 Public Class Form1    
    Private Sub BtnFah_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnFah.Click
        Try
            Dim intFah As Integer
            intFah = CInt(TxtBoxTemp.Text)
            intFah = (intFah * 9) / 5 - 32
            If MessageBox.Show(intFah.ToString & ControlChars.CrLf & "Would you like to start another temp conversion?", "Result", MessageBoxButtons.YesNo) = DialogResult.Yes Then
                TxtBoxTemp.Text = String.Empty
            End If
        Catch
            MessageBox.Show("Would you like to start another temp conversion?", "System Error", MessageBoxButtons.YesNo)

        End Try
    End Sub
End Class
于 2013-03-20T04:02:03.243 回答
2

MessageBox.Show返回一个DialogResult。你应该检查DialogResult.Yes

If MessageBox.Show(...) = DialogResult.Yes Then
   TxtBoxTemp.Text = String.Empty
End If
于 2013-03-20T04:02:06.817 回答
0

尝试这个...

If MessageBox.Show("Your Message", "Title", MessageBoxButtons.YesNo) = DialogResult.Yes Then
textbox.clear()
End If
于 2013-03-20T04:17:06.060 回答
0

使用Q作为变量,dim作为msgboxresult使msgbox有结果,如果按yes,文本框将被清除,如果没有,则返回或不执行任何操作

 Dim q As MsgBoxResult
            q = MsgBox("Your Question", vbYesNo)
            If q = vbYes Then
                TextBox1.Clear()
            Else
                Return
            End If
于 2013-03-20T04:06:41.643 回答