trouble with masked text boxes!

Grinski

Member
Joined
Apr 16, 2010
Messages
7
Programming Experience
Beginner
When i click in a normal text box, the cursor moves to the start, as you would expect. However, when i click on my masked text box, which i have set up to force numeric inputs, the cursor stays where it is, which could easily be in the middle! And if they start typing something like an 8 digit student number starting at the 4th spot, they'll only get 4 digits into it!

My mask is 999999999 and 9 in the mask help file is

"Digit or space, optional."


This should be fine for any number up to 9 digits long but i need to be able to account for people typing anything from "1" to "999999999" without knowing in advance how many digits they'll type or whereabouts in the text box they'll start typing. I want to move the cursor to the start if they click inside and the maskedbox.text = "". Is there any way to do that? :confused:

Maybe i should abandon using masked text boxes? The data validation functions might have made them obsolete? The trouble is i've created a lot of them and are now short on time :(
 
I took your suggestion, wrote the following and it does the job! Thanks for your help, much appreciated!

Private Sub MaskedTextBox_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles MaskedTextBox.MouseDown
' MsgBox(sender.Text)

If sender.Text = "" Then
sender.SelectionStart = 0
sender.SelectionLength = 0
End If


End Sub
 
Back
Top