textbox1失去焦点,检查输入的值是否为数字。
textbox2中按下Enter键,检查输入的值是否为数字。
textbox3获得焦点,计算textbox1和textbox2的和。
Public Class Form1
Private Sub TextBox1_LostFocus(sender As Object, e As EventArgs) Handles TextBox1.LostFocus
If Not IsNumeric(TextBox1.Text) Then
TextBox1.Text = ""
TextBox1.Focus()
End If
End Sub
Private Sub TextBox2_KeyUp(sender As Object, e As KeyEventArgs) Handles TextBox2.KeyUp
If e.KeyValue = 13 Then
If Not IsNumeric(TextBox2.Text) Then
TextBox2.Text = ""
End If
End If
End Sub
Private Sub TextBox3_GotFocus(sender As Object, e As EventArgs) Handles TextBox3.GotFocus
TextBox3.Text = Val(TextBox1.Text) + Val(TextBox2.Text)
End Sub
End Class