首页 > 开发 > 综合 > 正文

IP地址输入控件 V1.0.1.1版(FOR Win Form)

2024-07-21 02:24:25
字体:
来源:转载
供稿:网友
核心代码:

'只允许输入数字、"."
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

当运行时:

当出现错误时:
发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表