C# .NET 中“,”(逗号)和“.”(点)的 KeyCode 是什么?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/8915626/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-09 05:09:16  来源:igfitidea点击:

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

c#.netvb.netenumskeycode

提问by Bosak

In my KeyDownEventHandlerI need to know what is the KeyCodefor "," and ".".

在我的KeyDownEventHandler我需要知道什么是KeyCode“,”和“。”。

I can't find them thats why I ask. Thanks!

我找不到他们,这就是我问的原因。谢谢!

采纳答案by CodesInChaos

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.

键和字符不是一回事。键盘布局在它们之间进行转换,而这种转换并非微不足道。使用KeyDown. 如果您想知道用户输入了哪个字符,您应该使用KeyPress,它给出了已翻译的字符。

For example Keys.Decimalis a key on the numpad that corresponds to .on the US layout, and ,on the German layout. Keys.Oemcommaand OemPeriodare likely ,and .belows the letters. But on other layouts that may be different.

例如Keys.Decimal,小键盘上的一个键对应.于美式布局和,德式布局。Keys.OemcommaOemPeriod有可能,.初级讲座的字母。但在其他布局上可能会有所不同。

回答by Oded

Oemcommaand OemPeriodlook like good candidates.

Oemcomma并且OemPeriod看起来像不错的候选人。

Look at the Keysenumerationon MSDN.

查看MSDN上的Keys枚举

回答by jgauffin

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:
  1. 创建了一个带有单个文本框的 WinForm 项目。
  2. 添加了 keydown 事件处理程序。
  3. 在里面放一个断点
  4. 明白啦:

enter image description here

在此处输入图片说明

回答by D Stanley

Use Keys.Oemcommaand Keys.OemPeriod

使用Keys.OemcommaKeys.OemPeriod

回答by Shaun07776

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

查看十进制值,这是您的密钥代码。

http://www.asciitable.com/

http://www.asciitable.com/

回答by Champu

Have you tried this "."c

你试过这个“.”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