0

我正在尝试使用 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
4

3 回答 3

0

读起来好像MessageBox.Text = "",但我无权访问 Visual Basic,所以我不能确定。

于 2013-03-20T03:05:12.973 回答
0

您没有存储消息框中的结果....行:

If intFah = Windows.Forms.DialogResult.Yes

不正确,因为您试图将计算的温度与对话结果进行比较。

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

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

TxtBoxTemp.Text = String.Empty

但无论哪种方式都可以。

HTH,弥敦道

于 2013-03-20T03:08:08.147 回答
0

MessageBox.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
于 2013-03-20T03:22:52.503 回答