i. 新建一个TextBox,当用户在该控件中输入信息后,要移动到另一个控件之前,使用验证事件判断控件输入的是否为数字值;
ii. 循环上面窗体中的所有控件,用布尔函数判断TextBox中输入的是否为数字值;
iii. 如果不是数字值,用ErrorProvider在该控件上显示错误图标(提示信息中要列出该控件的名称),同时退出循环;
Private Sub TextBox1_Validating(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles TextBox1.Validating
ErrorProvider1.SetError(TextBox1, "")
If Not IsNumeric(TextBox1.Text) Then
ErrorProvider1.SetError(TextBox1, "TextBox1 error")
TextBox1.Focus()
End If
End Sub
Private Sub TextBox2_Validating(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles TextBox2.Validating
ErrorProvider2.SetError(TextBox2, "")
If Not IsNumeric(TextBox2.Text) Then
ErrorProvider1.SetError(TextBox1, "TextBox2 error")
TextBox2.Focus()
End If
End Sub
Private Sub TextBox3_Validating(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles TextBox3.Validating
ErrorProvider3.SetError(TextBox3, "")
If Not IsNumeric(TextBox1.Text) Then
ErrorProvider1.SetError(TextBox1, "TextBox3 error")
TextBox3.Focus()
End If