45fan.com - 路饭网

搜索: 您的位置主页 > 网络频道 > 阅读资讯:IP地址输入控件V1.0.1.1版的方法

IP地址输入控件V1.0.1.1版的方法

2016-09-01 06:58:01 来源:www.45fan.com 【

IP地址输入控件V1.0.1.1版的方法

核心代码:

'只允许输入数字、"."
Private Sub txtField_KeyPress(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles txtField0.KeyPress, txtField1.KeyPress, txtField2.KeyPress, txtField3.KeyPress
If e.KeyChar = "." Then
Dim tx As TextBox = CType(sender, TextBox)
'最后的文本框不可以输入"."
'在其它文本框输入".",相当于输入"Tab"键,即光标到下一文本框
If tx.Text = "" Or tx.SelectedText <> "" Then
e.Handled = True
End If
If tx.Name <> "txtField3" Then
SendKeys.Send("{TAB}")
Else
'最后的文本框不可以输入"."
e.Handled = True
End If
ElseIf (Not IsNumeric(e.KeyChar)) And e.KeyChar <> ControlChars.Back Then
e.Handled = True
Else
Dim tx As TextBox = CType(sender, TextBox)
If (Len(tx.Text) = 2 And e.KeyChar <> ControlChars.Back And tx.SelectedText.Length = 0) Then
If tx.Name <> "txtField3" Then
SendKeys.Send("{TAB}")
End If
End If
End If
'控制ControlChars.Back退格键
Dim tx1 As TextBox = CType(sender, TextBox)
If (Len(tx1.Text) = 0 And e.KeyChar = ControlChars.Back) Then
Select Case tx1.Name
Case "txtField3"
If txtField3.Text = "" Then
txtField2.Focus()
End If
Case "txtField2"
If txtField2.Text = "" Then
txtField1.Focus()
End If
Case "txtField1"
If txtField1.Text = "" Then
txtField0.Focus()
End If
End Select
End If
End Sub

当运行时:
IP地址输入控件V1.0.1.1版的方法
当出现错误时:
IP地址输入控件V1.0.1.1版的方法

 

本文地址:http://www.45fan.com/a/question/70562.html
Tags: 输入 控件 地址
编辑:路饭网
关于我们 | 联系我们 | 友情链接 | 网站地图 | Sitemap | App | 返回顶部