Try this. Set your form's KeyPreview property to True and drop a Label to it (named Label1) then paste this code in. Now run it and try to type some values using the keyboard.
Code:Private Sub Form1_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles Me.KeyPress Dim curTxt As String = Label1.Text.Replace(":", "") If curTxt.Length < 6 Then Dim ch As Char = e.KeyChar If Char.IsNumber(ch) Then curTxt &= ch If curTxt.Length > 2 Then For i As Integer = curTxt.Length - 2 To 1 Step -2 curTxt = curTxt.Insert(i, ":") Next End If Label1.Text = curTxt Else Beep() End If Else Beep() End If End Sub




Reply With Quote