Masked Textbox Prompt
-
Hello! I've been having some issues with masked textboxes and have been unable to find a solution, so I hope one of you knowledgeable forumers can point me in the right direction. Let's say for example I have a masked textbox and I want to restrict it to a 4digit numeric-only ID#. The Mask is set as "0000" and the PromptChar is "_". My problem arises when I run the project and enter the textbox. The | is placed at the end of the Prompt "____" and in order to input the data I want properly I need to backspace, key over, or click to the beginning of the string. How can I have a masked textbox always place the data entry marker (what's it called?) at the beginning of the Prompt string when the textbox becomes the selected control? Any help would be hugely appreciated. Thanks in advance!
-
Hello! I've been having some issues with masked textboxes and have been unable to find a solution, so I hope one of you knowledgeable forumers can point me in the right direction. Let's say for example I have a masked textbox and I want to restrict it to a 4digit numeric-only ID#. The Mask is set as "0000" and the PromptChar is "_". My problem arises when I run the project and enter the textbox. The | is placed at the end of the Prompt "____" and in order to input the data I want properly I need to backspace, key over, or click to the beginning of the string. How can I have a masked textbox always place the data entry marker (what's it called?) at the beginning of the Prompt string when the textbox becomes the selected control? Any help would be hugely appreciated. Thanks in advance!
use the SelectionStart property to set the position of the cursor (with nothing selected)
Panic, Chaos, Destruction. My work here is done.
-
use the SelectionStart property to set the position of the cursor (with nothing selected)
Panic, Chaos, Destruction. My work here is done.
-
It baffles me why this property isn't actually IN the properties list for masked textboxes! Thanks william. Am I going to have to use an Enter event for every masked textbox in order to do this?
I don't know why the control can't have some sane behaviour. It is rather pants, btu there you go. Try writting a single Enter event handler and using it to for all your controls.
Panic, Chaos, Destruction. My work here is done.
-
I don't know why the control can't have some sane behaviour. It is rather pants, btu there you go. Try writting a single Enter event handler and using it to for all your controls.
Panic, Chaos, Destruction. My work here is done.
-
private void txtCustID_Enter(object sender, EventArgs e)
{
txtCustID.SelectionStart = 0;
}Am I using the property incorrectly? I'm still having the same problem.
You are using the property well, but on checking back you have the wrong event:
private void maskedEdit\_GotFocus(object sender, EventArgs e) { MaskedTextBox mtb = (MaskedTextBox)sender; mtb.SelectionStart = 0; }
It appears that after the Enter event, the selection is set to the previous values. But if you use GotFocus it works. Just add the event handler manually after
InitializeComponent
in the constructor:InitializeComponent(); maskedTextBox1.GotFocus += new EventHandler(this.maskedEdit\_GotFocus); maskedTextBox2.GotFocus += new EventHandler(this.maskedEdit\_GotFocus);
Panic, Chaos, Destruction. My work here is done.