-
Feb 23rd, 2017, 04:14 PM
#1
Thread Starter
Lively Member
[RESOLVED] Masked textbox displays numbers in reverse order
Hello friends:
I have a masked textbox on a form, masked to handle phone numbers and requiring all numbers, I mean000)000-0000
I found an issue with it, since it receives the numbers where the user clicks. Therefore I used the SelectionStart property under a keydown event. The code is below.
It takes the cursor to the beguinning, but the numbers are entered or received in reverse order. I mean, the number (754)963-9183 is entered or received as (381)936-9457.
HTML Code:
Private Sub TelefonoMKTxt_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles TelefonoMKTxt.KeyDown
TelefonoMKTxt.SelectionStart = 0
End Sub
Any help will be appreciated.
Nelson
-
Feb 23rd, 2017, 04:21 PM
#2
Re: Masked textbox displays numbers in reverse order
Anytime that you type in TelefonoMKTxt it will send the caret to the start, this is why it is prepending values instead of appending them. Why are you setting the SelectionStart in the first place?
-
Feb 23rd, 2017, 06:20 PM
#3
Thread Starter
Lively Member
Re: Masked textbox displays numbers in reverse order
Hello dday9,
Thanks for the response.
your answer is quite logical.
I used SelectionStart because when I enter the masked textbox the cursor starts where I clicked. Therefore, the numbers I am tipying enter at that point. Since the point usually is not the start one of the masked textbox, the end of the mask is reached, but the complte phone nunber has not been entered. I just suposed that by getting the very beguinning of the masked textbox, the necesary places for all of the digits were going to be granted.
If you know a way to solved this issue, it will be welcome.
Thank you againg.
Nelson
-
Feb 23rd, 2017, 06:49 PM
#4
Re: Masked textbox displays numbers in reverse order
Using SelectionStart is ok to set the position... but doing it in the KeyDown event is an odd choice, because then it happens every time a key is pressed.
It would make more sense to use an event related to receiving the focus (such as GotFocus), or a mouse related event (such as MouseDown).
It may also make sense to set the position to just after the last character entered, rather than at the start (for situations where the user starts typing the number, but pops back to something else before finishing).
-
Feb 23rd, 2017, 07:03 PM
#5
Thread Starter
Lively Member
Re: Masked textbox displays numbers in reverse order
Thank you si_the_geek.
With Mousedown It works great.
Thanks to dday9 too.
Nelson
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|