2013-03-20 89 views
-1

我想出了如何清除文本框,但是当我在MessageBox上按时清除了该文本框。我想清除用户是否选择。如果用户选择那么我想什么都不做。使用MessageBox清除文本框是按钮

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 

回答

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 
0

运用Q作为变量,暗淡的msgboxresult来取得了MSGBOX有结果,如果按是,文本框将会清楚,如果不是,那么它将返回或什么都不做

Dim q As MsgBoxResult 
      q = MsgBox("Your Question", vbYesNo) 
      If q = vbYes Then 
       TextBox1.Clear() 
      Else 
       Return 
      End If 
+0

你有downvote前检查? – Kasnady 2013-03-20 04:24:09

+0

你可以考虑添加一个关于OP在做什么错误的评论,你的代码是干什么的,等等。 – Jeff 2013-03-20 04:26:15

+0

我只是回答了问题 – Kasnady 2013-03-20 04:28:34

0

尝试......

If MessageBox.Show("Your Message", "Title", MessageBoxButtons.YesNo) = DialogResult.Yes Then 
textbox.clear() 
End If 
+0

谢谢。我明白了。 – user2189046 2013-03-22 00:41:21