Jump to content
  • Advertisement
Sign in to follow this  
fafanne

[.net] Programmatically setting hilight on MaskedTextBox

This topic is 3829 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hello! Can somebody tells me how to highlight a maskedtextbox in C-Sharp?? I made it with a textbox but when I try to make it with the maskedtextbox it doesn't work! Here is my code: private void masBIRTHDATE_Enter(object sender, EventArgs e) { masBIRTHDATE.SelectionStart = 0; masBIRTHDATE.SelectionLength = 8; } Usually On my form when pressing tab, it goes in a textbox whose text will be highlighted. [edit by jpetrie: all-caps titles do not make me happy]

Share this post


Link to post
Share on other sites
Advertisement
maskedTextBox1.Enter += new EventHandler(maskedTextBox1_Enter);

void maskedTextBox1_Enter(object sender, EventArgs e)
{
maskedTextBox1.SelectionStart = 4;
maskedTextBox1.SelectionLength = 10;
}

Works fine for me...

theTroll

Share this post


Link to post
Share on other sites
Quote:
Original post by TheTroll
maskedTextBox1.Enter += new EventHandler(maskedTextBox1_Enter);

void maskedTextBox1_Enter(object sender, EventArgs e)
{
maskedTextBox1.SelectionStart = 4;
maskedTextBox1.SelectionLength = 10;
}

Works fine for me...

theTroll


Hi theTroll.
I forgot to mention something! Update the Mask Property of the maskedtextbox to "00-00-0000" in the property window. Then at runtime enter a date. You will see that the highlight doesn't work when the focus comes back on the maskedtextbox.

But leaving the Mask property to blank will make it work. Im trying to find a solution to it but in vain. In VB6 I remember I did that and it worked but not in C-Sharp. I think there are additional steps.

Please let me know if you find a solution to it. Thanks.

fafanne

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!