What is the KeyCode for “,”(comma) and “.”(dot) in .NET?

我是研究僧i 提交于 2019-11-28 21:14:30

A key and a character are not the same thing. The keyboard layout transforms between them, and that transform isn't trivial. Probably you're doing the wrong thing when using KeyDown. If you want to know which character a user entered you should use KeyPress, which gives the the already translated character.

For example Keys.Decimal is a key on the numpad that corresponds to . on the US layout, and , on the German layout. Keys.Oemcomma and OemPeriod are likely , and . belows the letters. But on other layouts that may be different.

Oemcomma and OemPeriod look like good candidates.

Look at the Keys enumeration on MSDN.

I did this:

  1. Created a WinForm project with a single textbox.
  2. Added the keydown event handler.
  3. Put a break point in it
  4. Got this:

Check out the decimal value, that's your key code.

http://www.asciitable.com/

D Stanley

Use Keys.Oemcomma and Keys.OemPeriod

Champu

Have you tried this "."c

A float filter:

Select Case e.KeyChar
    Case "0"c To "9"c
    Case "."c
        If .Text.Contains(".") Then
            e.Handled = True
        End If
    Case ChrW(Keys.Delete), ChrW(Keys.Back)
    Case Else
        e.Handled = True
End Select
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!