Solved

Cursor position inside MaskedTextBox

Posted on 2008-10-11
3
964 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
  • 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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

It’s quite interesting for me as I worked with Excel using vb.net for some time. Here are some topics which I know want to share with others whom this might help. First of all if you are working with Excel then you need to Download the Following …
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

759 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now