实现一个IP地址输入控件(自定义控件)
实现一个IP地址输入控件(自定义控件),要求能够对IP地址的每一段输入内容的符合性进行及时判断:u每个Box只能输入最多3个数字且小于256,第一个Box的第一个字符不为...
实现一个IP地址输入控件(自定义控件),要求能够对IP地址的每一段输入内容的符合性进行及时判断:
u 每个Box只能输入最多3个数字且小于256,第一个Box的第一个字符不为0
u 支持Tab键控制输入焦点在Box之间切换
u 支持方向键控制输入焦点在Box之间切换
u 前一个Box输入3个字符后,输入焦点自动切换到下一个Box 展开
u 每个Box只能输入最多3个数字且小于256,第一个Box的第一个字符不为0
u 支持Tab键控制输入焦点在Box之间切换
u 支持方向键控制输入焦点在Box之间切换
u 前一个Box输入3个字符后,输入焦点自动切换到下一个Box 展开
2个回答
展开全部
'搞定:
'1,先新建一个工程,添加四个TextBox,名称分别为Text1,Text2,Text3,Text4
'2,双击窗体,Ctrl+A
'3,复制以下所有代码然后,Ctrl+V
'4,采纳,加分
'5,没用做控件,随手就这么写了一下,有兴趣,可以参考来做控件
Option Explicit
Private Sub Form_Load()
Text1.TabIndex = 0: Text1.TabStop = True
Text2.TabIndex = 1: Text2.TabStop = True
Text3.TabIndex = 2: Text3.TabStop = True
Text4.TabIndex = 4: Text4.TabStop = True
End Sub
Private Sub Text1_KeyDown(KeyCode As Integer, Shift As Integer)
If KeyCode = 39 Or KeyCode = 40 Or KeyCode = 110 Then
Text2.SetFocus: Text2.SelStart = 0: Text2.SelLength = Len(Text2.Text)
ElseIf KeyCode = 37 Or KeyCode = 38 Then
Text4.SetFocus: Text4.SelStart = 0: Text4.SelLength = Len(Text4.Text)
End If
End Sub
Private Sub Text1_KeyPress(KeyAscii As Integer)
Dim str As String
If KeyAscii = 8 Then Exit Sub
str = Text1.Text
Select Case Len(str)
Case Is = 0
If KeyAscii < 49 Or KeyAscii > 50 Then
KeyAscii = 0
End If
Case Is = 1
If KeyAscii < 48 Or KeyAscii > 57 Then
KeyAscii = 0
Else
If CLng(str & Chr(KeyAscii)) > 25 Then KeyAscii = 0
End If
Case Is = 2
If KeyAscii < 48 Or KeyAscii > 57 Then
KeyAscii = 0
Else
If CLng(str & Chr(KeyAscii)) > 255 Then
KeyAscii = 0
Else
Text2.SetFocus: Text2.SelStart = 0: Text2.SelLength = Len(Text2.Text)
End If
End If
Case Else
KeyAscii = 0
End Select
End Sub
Private Sub Text2_KeyDown(KeyCode As Integer, Shift As Integer)
If KeyCode = 39 Or KeyCode = 40 Or KeyCode = 110 Then
Text3.SetFocus: Text3.SelStart = 0: Text3.SelLength = Len(Text3.Text)
ElseIf KeyCode = 37 Or KeyCode = 38 Then
Text1.SetFocus: Text1.SelStart = 0: Text1.SelLength = Len(Text1.Text)
End If
End Sub
Private Sub Text2_KeyPress(KeyAscii As Integer)
Dim str As String
str = Text2.Text
If KeyAscii = 8 Then Exit Sub
Select Case Len(str)
Case Is = 0
If KeyAscii < 48 Or KeyAscii > 50 Then
KeyAscii = 0
End If
Case Is = 1
If KeyAscii < 48 Or KeyAscii > 57 Then
KeyAscii = 0
Else
If CLng(str & Chr(KeyAscii)) > 25 Then KeyAscii = 0
End If
Case Is = 2
If KeyAscii < 48 Or KeyAscii > 57 Then
KeyAscii = 0
Else
If CLng(str & Chr(KeyAscii)) > 255 Then
KeyAscii = 0
Else
Text3.SetFocus: Text3.SelStart = 0: Text3.SelLength = Len(Text3.Text)
End If
End If
Case Else
KeyAscii = 0
End Select
End Sub
Private Sub Text3_KeyDown(KeyCode As Integer, Shift As Integer)
If KeyCode = 39 Or KeyCode = 40 Or KeyCode = 110 Then
Text4.SetFocus: Text4.SelStart = 0: Text4.SelLength = Len(Text4.Text)
ElseIf KeyCode = 37 Or KeyCode = 38 Then
Text2.SetFocus: Text2.SelStart = 0: Text2.SelLength = Len(Text2.Text)
End If
End Sub
Private Sub Text3_KeyPress(KeyAscii As Integer)
Dim str As String
str = Text3.Text
If KeyAscii = 8 Then Exit Sub
Select Case Len(str)
Case Is = 0
If KeyAscii < 48 Or KeyAscii > 50 Then
KeyAscii = 0
End If
Case Is = 1
If KeyAscii < 48 Or KeyAscii > 57 Then
KeyAscii = 0
Else
If CLng(str & Chr(KeyAscii)) > 25 Then KeyAscii = 0
End If
Case Is = 2
If KeyAscii < 48 Or KeyAscii > 57 Then
KeyAscii = 0
Else
If CLng(str & Chr(KeyAscii)) > 255 Then
KeyAscii = 0
Else
Text4.SetFocus: Text4.SelStart = 0: Text4.SelLength = Len(Text4.Text)
End If
End If
Case Else
KeyAscii = 0
End Select
End Sub
Private Sub Text4_KeyDown(KeyCode As Integer, Shift As Integer)
If KeyCode = 39 Or KeyCode = 40 Or KeyCode = 110 Then
Text1.SetFocus: Text1.SelStart = 0: Text1.SelLength = Len(Text1.Text)
ElseIf KeyCode = 37 Or KeyCode = 38 Then
Text3.SetFocus: Text3.SelStart = 0: Text3.SelLength = Len(Text3.Text)
End If
End Sub
Private Sub Text4_KeyPress(KeyAscii As Integer)
Dim str As String
str = Text4.Text
If KeyAscii = 8 Then Exit Sub
Select Case Len(str)
Case Is = 0
If KeyAscii < 48 Or KeyAscii > 50 Then
KeyAscii = 0
End If
Case Is = 1
If KeyAscii < 48 Or KeyAscii > 57 Then
KeyAscii = 0
Else
If CLng(str & Chr(KeyAscii)) > 25 Then KeyAscii = 0
End If
Case Is = 2
If KeyAscii < 48 Or KeyAscii > 57 Then
KeyAscii = 0
Else
If CLng(str & Chr(KeyAscii)) > 255 Then
KeyAscii = 0
Else
Text1.SetFocus: Text1.SelStart = 0: Text1.SelLength = Len(Text1.Text)
End If
End If
Case Else
KeyAscii = 0
End Select
End Sub
Storm代理
2023-07-25 广告
2023-07-25 广告
StormProxies是一家可靠的代理服务提供商,提供原生IP(住宅原生IP)和高匿名代理服务。以下是关于StormProxies的原生IP服务的一些信息:1. 住宅原生IP:StormProxies提供的住宅原生IP是指从真实的家庭或企...
点击进入详情页
本回答由Storm代理提供
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询