Click here to Skip to main content
15,898,134 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
HI,

I Have requirement to enter the phone numbers in a masked text box for the US based numbers like in the below format
(999)-000-0000

Here the problem is when the masked text box is focused the cursor starts before "(" Symbol

But i need the cursor starts after "(" symbol

I wrote a code for Mouse Click Event and it works fine but for keyboard tab its not

My Sample Code is:
C#
The Belowcode is working fine for Mouse click event
   private void txtPhone_MouseClick(object sender, MouseEventArgs e)
    {
      txtPhone.SelectionStart = 1;
    }            

The Below Code is not working for Focus on Masked TextBox
   private void txtPhone_Enter(object sender, EventArgs e)
    {
      txtPhone.SelectionStart = 1;
    }


Thanks In Advance......
sudhakar
Posted
Updated 31-Aug-11 3:26am
v3
Comments
Prerak Patel 31-Aug-11 2:25am    
Use code block for code segments.
BobJanova 31-Aug-11 11:16am    
Did you try handling GotFocus instead of Enter?

1 solution

When you select the MaskedTextBox using "(999) 000-0000" as the Mask, yes, the insertion cursor appears left of the left-parenthesis.

But, you'll notice: that the moment you start typing a number the number is entered, as you might expect, after the left-parenthesis. So, is this really a big deal ?

If you are really bothered by this very minor behavior, use a mask like "000 - 000 - 0000" and you can have the insertion cursor as you wish.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900