检测Textbox-VB.NET中的数字键
我想在文本框按键事件中检测numpad的数字键,实际上我只想允许用户从numpad而不是从字母数字键盘输入数字 如果数字不是来自键盘的numpad,则事件应为cancel 除了检测Textbox-VB.NET中的数字键,.net,vb.net,.net,Vb.net,我想在文本框按键事件中检测numpad的数字键,实际上我只想允许用户从numpad而不是从字母数字键盘输入数字 如果数字不是来自键盘的numpad,则事件应为cancel 除了GetAsyncKeyState()之外,还有其他方法可以完成此任务吗 目前我正在尝试这个代码 If e.KeyChar = Chr(49) Then '48 to 57 are the char codes for "0 to 9" of alphanumeric keypad. e.Handled = Tr
GetAsyncKeyState()
之外,还有其他方法可以完成此任务吗
目前我正在尝试这个代码
If e.KeyChar = Chr(49) Then '48 to 57 are the char codes for "0 to 9" of alphanumeric keypad.
e.Handled = True
End I
使用
GetAsyncKeyState()
是我的最后一个优先事项,因为它会降低我的应用程序的性能。键盘0-9是键码96到105
KEY CODE
------------------
numpad 0 96
numpad 1 97
numpad 2 98
numpad 3 99
numpad 4 100
numpad 5 101
numpad 6 102
numpad 7 103
numpad 8 104
numpad 9 105
有两种方法可以检查这一点
If (e.KeyCode >= Keys.NumPad0 and e.KeyCode <= Keys.NumPad9) Then ...
我知道numpad 0是96,字母数字pad 0是47,问题是如何检测?我的代码两个都返回47(1)。谢谢,问题解决了,我应该使用
KeyDown
事件而不是keypress
。
If Char.IsDigit(e.KeyChar) Then ....