Hi
Here is a variation. This will stop user from moving to next MTB if current one is not complete, and will auto move to next one if complete.
' MaskedTextBoxes
Option Strict On
Option Explicit On
Public Class Form1
WithEvents mtb As MaskedTextBox
WithEvents tb As New TextBox
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
' set up some (4) maskedtextboxes
Dim x As Integer = 10
Dim y As Integer = 20
For i As Integer = 1 To 4
mtb = New MaskedTextBox
With mtb
.Name = "MaskedTextBox" & i.ToString
.BackColor = Color.Pink
.Tag = i
.Mask = "00 - 00 - 00"
.Font = New Font(.Font.FontFamily, 18)
.TextAlign = HorizontalAlignment.Center
.Location = New Point(10, y)
.Width = 200
y += 44
AddHandler .Validated, AddressOf MaskedTextBox_Validated
AddHandler .KeyUp, AddressOf MaskedTextBox_KeyUp
End With
Controls.Add(mtb)
Next
' add a random textbox
With tb
.Font = New Font(.Font.FontFamily, 18)
.Text = "Some random text"
.Location = New Point(10, y + 10)
.BackColor = Color.WhiteSmoke
.Width = 200
End With
Controls.Add(tb)
End Sub
Private Sub MaskedTextBox_Validated(sender As Object, e As EventArgs)
' checks if current MTB is complete
' if not, remain there.
Dim mtb As MaskedTextBox = DirectCast(sender, MaskedTextBox)
tb.Text = String.Empty
If Not mtb.MaskFull Then
tb.Text = mtb.Text
MessageBox.Show(mtb.Name & " Needs full Sort Code")
mtb.Select()
End If
End Sub
Private Sub MaskedTextBox_KeyUp(sender As Object, e As KeyEventArgs)
' checks if current MTB is full and
' if so, moves to next which
' ends at the random TextBox
Dim mtb As MaskedTextBox = DirectCast(sender, MaskedTextBox)
If mtb.MaskFull Then
SendKeys.Send(vbTab)
End If
End Sub
End Class