2015-02-08 67 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