470,631 Members | 2,140 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 470,631 developers. It's quick & easy.

MaskedTextBox Cursor Position

We have some dumb and lazy people here, so I need help.

To fix the dumb part: We have placed MaskedTextBoxes on the forms so they
will stop entering the information incorrectly.

Now the lazy part: When our people click on a blank MaskedTextBox field, the
cursor does not automatically go to the first "non-filled" mask value.

For Example: Take the MaskedTextBox "___-___-___". When our people click the
Text area, their cursor may stop at "___-_|_-___" (as noted by the '|'
character) instead of "|__-___-___" (the start of the Text area).

As another Example: Take the partially filled MaskedTextBox "123-4__-___".
When our people mouse-click into the Text area, the cursor should position
anywhere between position 0 and 5, not where the click event happened.

I realize this is happening because the control's Text field is physically
populated with the mask, and I am trying to work around this programmatically
in the code.

In my MaskedTextBox, I have set the CutCopyMaskFormat Property to
"ExcludePromptAndLiterals," but this did not solve my problem.

Also, I have tried setting the SelectionStart property whenever the control
receives focus, but this does not move the cursor.

How do I position the cursor in a MaskedTextBox?
Feb 11 '08 #1
1 8685
In the mouse up event of maskedtextbox write the following code........
SendKeys.Send("{HOME}")

Whenever you will enter your mouse in the textbox,the cursor will be moved to the starting position.....

Aug 27 '08 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by Dan H. | last post: by
1 post views Thread by Tantra Veda | last post: by
1 post views Thread by objectref | last post: by
1 post views Thread by Paul | last post: by
3 posts views Thread by Mike Fellows | last post: by
reply views Thread by =?Utf-8?B?Sm9hY2hpbQ==?= | last post: by
1 post views Thread by eljainc | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.