?
Solved

Cursor position inside MaskedTextBox

Posted on 2008-10-11
3
Medium Priority
?
1,149 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 2000 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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Article by: jpaulino
XML Literals are a great way to handle XML files and the community doesn’t use it as much as it should.  An XML Literal is like a String (http://msdn.microsoft.com/en-us/library/system.string.aspx) Literal, only instead of starting and ending with w…
Microsoft Reports are based on a report definition, which is an XML file that describes data and layout for the report, with a different extension. You can create a client-side report definition language (*.rdlc) file with Visual Studio, and build g…
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…
Are you ready to place your question in front of subject-matter experts for more timely responses? With the release of Priority Question, Premium Members, Team Accounts and Qualified Experts can now identify the emergent level of their issue, signal…

650 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