Solved

Cursor position inside MaskedTextBox

Posted on 2008-10-11
3
1,026 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

Technology Partners: 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

I think the Typed DataTable and Typed DataSet are very good options when working with data, but I don't like auto-generated code. First, I create an Abstract Class for my DataTables Common Code.  This class Inherits from DataTable. Also, it can …
If you're writing a .NET application to connect to an Access .mdb database and use pre-existing queries that require parameters, you've come to the right place! Let's say the pre-existing query(qryCust) in Access takes a Date as a parameter and l…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

680 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