Vb.net 如何使用messageboxbuttons清除文本框。是否?

Vb.net 如何使用messageboxbuttons清除文本框。是否?,vb.net,Vb.net,我正在尝试使用messageboxbuttons.yesno清除文本框。如果他选择开始另一次转换,则清除文本框。我不知道怎么了。 公开课表格1 Private Sub BtnFah_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnFah.Click Try Dim intFah As Integer intFah =

我正在尝试使用messageboxbuttons.yesno清除文本框。如果他选择开始另一次转换,则清除文本框。我不知道怎么了。 公开课表格1

    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
            MessageBox.Show(intFah.ToString & ControlChars.CrLf & "Would you like to start another temp conversion?", "Result", MessageBoxButtons.YesNo)
            If intFah = Windows.Forms.DialogResult.Yes Then
                TxtBoxTemp.Clear()
            ElseIf intFah = Windows.Forms.DialogResult.No Then

            End If
        Catch
            MessageBox.Show("Would you like to start another temp conversion?", "System Error", MessageBoxButtons.YesNo)

        End Try
    End Sub
End Class

它就像
MessageBox.Text=”“
,但我没有访问Visual Basic的权限,所以我不能确定

您没有存储来自消息框的结果…行:

If intFah = Windows.Forms.DialogResult.Yes
不正确,因为您正在尝试将计算的温度与对话框结果进行比较

如果您遵循该示例,那么您应该了解如何从消息框中捕获结果,然后执行适当的操作

在VB上下文中,Clear()方法的使用也可以,另一种方法是:

TxtBoxTemp.Text = String.Empty
但两种方式都可以


嗯,Nathan

只要把
消息框.Show()直接放在
If

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) = Windows.Forms.DialogResult.Yes Then
            TxtBoxTemp.Text = String.Empty
        Else

        End If
    Catch
        MessageBox.Show("Would you like to start another temp conversion?", "System Error", MessageBoxButtons.YesNo)
    End Try
End Sub

谢谢,我成功了。:)谢谢,我成功了。:)当我按no时,它也会清除文本框。我对代码做了一些更改,但它不起作用。我能做什么?如果你仍然有问题,你应该发布你的代码(例如,编辑你的原始问题并插入不起作用的修订代码)-这将使帮助更容易