0

i have a little tiny problem, what i am trying to do is limit my textBox to the following characters: [a=>f, x, A=>F, 0=>9], and what i need exactly is add an exception that will make any lower case input in the mentioned textBox become uppercase, except for "x", this is what i tried, but it limited all inputs from the textBox:

if (!Char.IsDigit(e.KeyChar) && !Char.IsControl(e.KeyChar) && (e.KeyChar < 'A' || e.KeyChar > 'F') && (e.KeyChar < 'a' || e.KeyChar > 'f') && (e.KeyChar != ' '))
        {
            e.Handled = true;
            textBox1.CharacterCasing = CharacterCasing.Upper;
        }
        else if ((e.KeyChar != 'x'))
        {
            e.Handled = true;
            textBox1.CharacterCasing = CharacterCasing.Lower;
        }

Thank you.

4

1 回答 1

0

设法绕过它:

if (!Char.IsDigit(e.KeyChar) && !Char.IsControl(e.KeyChar) && (e.KeyChar < 'A' || e.KeyChar > 'F') && (e.KeyChar < 'a' || e.KeyChar > 'f') && (e.KeyChar != ' ') && (e.KeyChar != 'x'))
        {
            e.Handled = true;
        }
        //textBox1.CharacterCasing = CharacterCasing.Upper;
        if (e.KeyChar == 'x') e.KeyChar = Char.ToLower(e.KeyChar);
        else e.KeyChar = Char.ToUpper(e.KeyChar);

谢谢你。

于 2012-11-13T00:23:26.543 回答