我正在尝试使用messageboxbuttons.yesno清除文本框。如果他选择开始另一次转换,请清除文本框。我没错。 公共类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
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
答案 0 :(得分:0)
它reads好像MessageBox.Text = ""
,但我无法访问Visual Basic,所以我无法确定。
答案 1 :(得分:0)
您没有存储消息框中的结果....行:
If intFah = Windows.Forms.DialogResult.Yes
不正确,因为您正在尝试将您计算的温度与对话框结果进行比较。
如果您遵循示例here,那么您应该看到如何从消息框中捕获结果,然后执行相应的操作。
您在VB上下文中对Clear()方法的使用也是正常的,另一种方法是:
TxtBoxTemp.Text = String.Empty
但无论如何都可以。
HTH,Nathan答案 2 :(得分: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