开发者

C# KeyDown alphanumeric culture dependent !

开发者 https://www.devze.com 2022-12-22 01:53 出处:网络
How to determine if the pressed Key is an alphabetica开发者_开发问答l key regard to the culture specific keys:

How to determine if the pressed Key is an alphabetica开发者_开发问答l key regard to the culture specific keys:

e.g.:

'[' = 'ú' = 'ü' ... is the same key but with different value on different language Keyboards.

I've tried to compare the ordinal key value: (int)e.Key >= 0x20E ..and <= .. but it does not work well, as modifier keys have sometimes same ordinal codes.

Any idea? Thanks

EDITED:

Hmm and how about this ?

System.Text.RegularExpressions.Regex objAlphaNumericPattern = new System.Text.RegularExpressions.Regex("[^a-zA-Z0-9]");
            if (!objAlphaNumericPattern.IsMatch(e.Key.ToString()))      
            {
                lp.IsDropDownOpen = true;
            }


Is char.IsLetter method helpful in your case?

char.IsLetter('['); //Return false
char.IsLetter('ú'); //Return true

With your sample, we can write:

if (!char.IsLetterOrDigit((char)e.Key))
{
    lp.IsDropDownOpen = true;
}
0

精彩评论

暂无评论...
验证码 换一张
取 消