How to make auto calculate???

zahir

Member
Joined
Apr 9, 2009
Messages
9
Programming Experience
1-3
Hi everyone i have one question..

How to make auto calculation in textbox without press the button?
Example i have Textbox1 + Textbox2 = Textbox3
in the textbox3 it will auto calculate the value...
:confused::confused::confused:
 
Use the the TextChanged event:
VB.NET:
Private Sub TextBox2_TextChanged(ByVal sender As Object, ByVal e As EventArgs) Handles Textbox2.TextChanged
  Try
   If Not String.IsNullOrEmpty(Textbox1.Text) Then
      If Textbox2.Text.Length > 0 Then
         TextBox3.Text = Cint(Textbox1.Text) + Cint(Textbox2.Text)
      Else
         TextBox3.Text = String.Empty
      End If
   End If
  Catch
  End Try
End Sub
Also consider using the keypress to capture only number keystrokes, or errors you'll throw...
 
Personally, I would use a label in-place of textbox3, they won't need to edit this, it just holds the result.
 
Back
Top