Posted 16 years ago
by David Mullin

I wanted to add the equivalent of TextBox.CharacterCasing to a subclass of MaskedTextBox. I realize that I could do this in the Mask property, but for internal reasons, we'd like to handle it through this property.
However, I can't seem to find any place to intercept the text and force it to upper case. I tried trapping the TextChanged event, and put in a body like:but, while the code ran, the Text of the control never changed. Is there some better event to trap? Is there some other way to do this?
However, I can't seem to find any place to intercept the text and force it to upper case. I tried trapping the TextChanged event, and put in a body like:
if (string.IsNullOrEmpty(Text) == false)
{
string newText = Text;
if (CharacterCasing == CharacterCasing.Upper)
{
newText = newText.ToUpper();
}
else if (CharacterCasing == CharacterCasing.Lower)
{
newText = newText.ToLower();
}
if (Text != newText)
{
Text = newText;
}
}