2015-02-08 135 views
-1
Private Sub TextBox1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox1.TextChanged, TextBox2.TextChanged 
If String.IsNullOrEmpty(TextBox1.Text) OrElse String.IsNullOrEmpty(TextBox2.Text) Then Exit Sub 
If Not IsNumeric(TextBox1.Text) OrElse Not IsNumeric(TextBox2.Text) Then Exit Sub 
TextBox3.Text = CDbl(TextBox1.Text) + CDbl(TextBox2.Text) 
End Sub 

此代碼適用於我,但是當我刪除兩個文本框的值總仍然存在...我的問題的任何解決方案?自動計算

回答

0

當輸入TextBoxes(TextBox1和TextBox2)被清除時,沒有代碼可以從輸出TextBox(TextBox3)中刪除該值。您可以在TextChanged事件處理程序的開始處清除TextBox3。

Private Sub TextBox1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox1.TextChanged, TextBox2.TextChanged 
    TextBox3.Text = "" 
    If String.IsNullOrEmpty(TextBox1.Text) OrElse String.IsNullOrEmpty(TextBox2.Text) Then Exit Sub 
    If Not IsNumeric(TextBox1.Text) OrElse Not IsNumeric(TextBox2.Text) Then Exit Sub 
    TextBox3.Text = (CDbl(TextBox1.Text) + CDbl(TextBox2.Text)).ToString 
End Sub 
+0

它的工作原理!非常感謝你的兄弟:) – user3342642 2015-02-23 09:26:36