[.net] Programmatically setting hilight on MaskedTextBox

Started by
1 comment, last by fafanne 15 years, 10 months ago
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]
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
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

This topic is closed to new replies.

Advertisement