在窗体内加入控件text1,然后复制下面代码,运行即可(此功能不太完善,供参考):
Option Explicit
Private Sub Form_Load()
Text1.Text = " - - : : " '初始化格式
End Sub
Private Sub Text1_Change()
Select Case Text1.SelStart
Case 4, 7, 10, 13, 16 '位置控制
Text1.SelStart = Text1.SelStart + 1
End Select
End Sub
Private Sub Text1_KeyPress(KeyAscii As Integer)
Dim i As Long
With Text1
If IsNumeric(Chr(KeyAscii)) = False Then KeyAscii = 0: Exit Sub '非数字退出
i = .SelStart
If i = 19 Then '防止数字输入超出范围
KeyAscii = 0
Exit Sub
End If
.Text = Left(.Text, i) & Mid(.Text, i + 2)
.SelStart = i
End With
End Sub
追问复制粘贴的垃圾