textbox1失去焦点,检查输入的值是否为数字。
textbox2中按下Enter键,检查输入的值是否为数字。
textbox3获得焦点,计算textbox1和textbox2的和。
Public Class Form1Private Sub TextBox1_LostFocus(sender As Object, e As EventArgs) Handles TextBox1.LostFocusIf Not IsNumeric(TextBox1.Text) ThenTextBox1.Text = ""TextBox1.Focus()End IfEnd SubPrivate Sub TextBox2_KeyUp(sender As Object, e As KeyEventArgs) Handles TextBox2.KeyUpIf e.KeyValue = 13 ThenIf Not IsNumeric(TextBox2.Text) ThenTextBox2.Text = ""End IfEnd IfEnd SubPrivate Sub TextBox3_GotFocus(sender As Object, e As EventArgs) Handles TextBox3.GotFocusTextBox3.Text = Val(TextBox1.Text) + Val(TextBox2.Text)End Sub
End Class