Solved

Cursor position inside MaskedTextBox

Posted on 2008-10-11
3
1,045 Views
Last Modified: 2012-05-05
Hi, I'm using VB 2005, WinForms. I've added a MaskedTextBox to my Form and formatted it to accept telephone numbers [i.e. (999) 999-9999].

When the field has no data in it, it looks like this [(___) ___-_____]. However, when I tab over to the field, my cursor lands right before the first parentheses.  My cursor is represented here by the plus character (+) [i.e. +(___) ___-_____]. How do I get my cursor to begin inside the parentheses like this; [i.e. (+__) ___-_____]?

I don't see a "Padding" parameter in the control. How can I create one that will force the cursor to land where I want it to land?

Thanks,
Fulano
0
Comment
Question by:Mr_Fulano
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 48

Accepted Solution

by:
jpaulino earned 500 total points
ID: 22695478
Hi Fulano,
You can use the GotFocus event to place the cursor.
Try this way:

    Private Sub MaskedTextBox1_GotFocus(ByVal sender As Object, ByVal e As System.EventArgs) Handles MaskedTextBox1.GotFocus
        Me.MaskedTextBox1.Select(2, 0)
    End Sub

Open in new window

0
 

Author Comment

by:Mr_Fulano
ID: 22695516
Hi JPaulino, almost...it was

Me.MaskedTextBox1.Select(1, 0)

However, you had the right idea, I just think you had a typo in your response.

Thanks very much!
Fulano
0
 
LVL 48

Expert Comment

by:jpaulino
ID: 22695519
>> I just think you had a typo in your response.
LOL
Yes, it was a typo!
Gald I could help
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A while ago, I was working on a Windows Forms application and I needed a special label control with reflection (glass) effect to show some titles in a stylish way. I've always enjoyed working with graphics, but it's never too clever to re-invent …
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

738 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question