2013-03-20 82 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