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 :(得分: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