求vb代码!只能输入字母数字下划线!的vb代码!
1个回答
展开全部
在KeyDown事件里面把原来的内容保存在一个变量里面,然后在KeyUp里判断如果Keycode不是字母数字下划线就把原来的内容写回。
下面是例子:
Public YL As String
Private Sub Text1_KeyDown(KeyCode As Integer, Shift As Integer)
YL = Text1.Text
End Sub
Private Sub Text1_KeyUp(KeyCode As Integer, Shift As Integer)
If (KeyCode > 122 Or KeyCode < 127) Or KeyCode < 48 Or (KeyCode > 57 And KeyCode < 65) Or (KeyCode > 90 And KeyCode < 97) Then
Text1.Text = YL
End If
End Sub
下面是例子:
Public YL As String
Private Sub Text1_KeyDown(KeyCode As Integer, Shift As Integer)
YL = Text1.Text
End Sub
Private Sub Text1_KeyUp(KeyCode As Integer, Shift As Integer)
If (KeyCode > 122 Or KeyCode < 127) Or KeyCode < 48 Or (KeyCode > 57 And KeyCode < 65) Or (KeyCode > 90 And KeyCode < 97) Then
Text1.Text = YL
End If
End Sub
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询