Solved

Cursor position inside MaskedTextBox

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

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

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 …
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
In this video, viewers will be given step by step instructions on adjusting mouse, pointer and cursor visibility in Microsoft Windows 10. The video seeks to educate those who are struggling with the new Windows 10 Graphical User Interface. Change Cu…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…

690 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