1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36
| Public Class Form1
Private Sub TextBox1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox1.TextChanged
If (TextBox1.Text.Length = 2 Or TextBox1.Text.Length = 5) Then
TextBox1.Text = TextBox1.Text + "/"
TextBox1.SelectionStart = TextBox1.Text.Length
End If
If (TextBox1.Text.Length = 8) Then
Dim str As String = TextBox1.Text
Dim split_date As String() = str.Split("/")
Dim tDate As DateTime = New DateTime(Convert.ToInt32(split_date(2)), _
Convert.ToInt32(split_date(1)), _
Convert.ToInt32(split_date(0)))
TextBox1.Text = tDate.ToString("dd/MM/yyyy")
End If
End Sub
Private Sub TextBox2_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox2.TextChanged
If (TextBox2.Text.Length = 2) Then
TextBox2.Text = TextBox2.Text + ":"
TextBox2.SelectionStart = TextBox2.Text.Length
End If
If (TextBox2.Text.Length = 5) Then
Dim str As String = TextBox2.Text
Dim split_date As String() = str.Split(":")
Dim tDate As DateTime = New DateTime(Convert.ToInt32(split_date(1)), _
Convert.ToInt32(split_date(0)))
TextBox2.Text = tDate.ToString("h:mm")
End If
End Sub
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
TextBox1.MaxLength = 10
TextBox2.MaxLength = 5
End Sub
End Class |
Partager