仅允许在“ txtfirstname”和“ txtlastname”中输入字母。这两个事件都在一个例外下处理(每个教授),我不知道对两个事件分别使用什么声明。它的工作图像不存在(txtFirstName或Else txtLastName,“只能是字母”)。我可以使名字正常工作,但不能使名字和姓氏同时工作。
Private Sub OnlyLetter_KeyPress(sender As Object, e As KeyPressEventArgs) Handles txtFirstName.KeyPress, txtLastName.KeyPress
'prevents numbers from being entered into First name or Last name textbox
If Char.IsControl(e.KeyChar) Then Exit Sub
If Not Char.IsLetter(e.KeyChar) Then
e.Handled = True
errorProvider.SetError(txtFirstName OrElse txtLastName, "Can only be letters")
Else
errorProvider.SetError(txtFirstName, String.Empty)
End If
答案 0 :(得分:0)
您可以使用它。
Private Sub OnlyLetter_KeyPress(sender As Object, e As KeyPressEventArgs) Handles txtFirstName.KeyPress, txtLastName.KeyPress
If Char.IsControl(e.KeyChar) Then Exit Sub
If Not Char.IsLetter(e.KeyChar) Then
e.Handled = True
errorProvider.SetError(DirectCast(sender, Textbox) ,"Can only be letters")
Else
errorProvider.SetError(DirectCast(sender, Textbox) , String.Empty)
End If
End Sub