IP地址輸入控件 V1.0.1.1版(FOR Win Form)
2024-07-21 02:24:25
供稿:網(wǎng)友
核心代碼:
'只允許輸入數(shù)字、"."
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
當運行時:
當出現(xiàn)錯誤時: