用于检测ENTER的KeyDown或KeyPress [英] KeyDown or KeyPress to detect ENTER
问题描述
大家好,
我正在使用带有数字小键盘的WM2005(设备名称是Unitech的PA600)
当我尝试检测用户按下的Enter时,当我将焦点放在文本框上时,我无法得到它。
尝试在KeyDown上捕获它
private
void txtActivateDG_KeyDown( object sender, KeyEventArgs e){
if ((e.KeyValue == ' \ r' ))
{
//按下输入
//刷新DataGrid
//更新DataGrid选中新项目
}
}
尝试在KeyPress上捕获它
private
void txtActivateDG_KeyPress( object sender, KeyPressEventArgs e){
if ((e.KeyChar == '\ r' < font size = 2>))
{
//按Enter键
//刷新DataGrid < font size = 2>
//使用新项目更新DataGrid
}
}
两个选项都不要t得到ENTER键..(并且根本不进入该功能)
有什么想法吗?
我没有遇到任何其他数字函数。
当我对一个按钮有一个焦点时,没有问题捕获ENTER和按钮点击功能统计
其中告诉我,ENTER键盘是OL
当我使用KeyPress时,我有一个不同的问题,我键入somtimes 2-3一起输入,关闭用户按下的速度..我需要禁用不需要的额外的ENTER键。 (知道怎么做?)
Eran
抱歉,为了记录目的,为时已晚。
输入keychar = 13所以代码就是这样。
private void txtActivateDG_KeyPress(object sender,KeyPressEventArgs e)
{
if(e.KeyChar == 13)
{
//按下输入
//刷新DataGrid
//用新项更新DataGrid选择
}
}
如果你想消除不需要的输入键(例如,只有在按下多个输入键时才输入1在2秒内你将需要一个类型为 DateTime 的类级变量,你的代码将如下所示
DateTime FirstPress = DateTime.Now;
private void txtActivateDG_KeyPress(object s ender,KeyPressEventArgs e)
{
if((e.KeyChar == 13)&& (DateTime.Now.Subtract(FirstPress).TotalSeconds> 2))
{
FirstPress = DateTime.Now;
按++;
//按下输入
//刷新DataGrid
//使用选中的新项目更新DataGrid
}
}
Hi all,
I'm using a WM2005 that has a Numeric keypad (the device name is PA600 by Unitech)
When I try to detect an Enter pressed by the user I don't get it when I have a focus on a textbox.
Try to catch it on KeyDown
private
void txtActivateDG_KeyDown(object sender, KeyEventArgs e){
if ((e.KeyValue == '\r')){
//Pressed Enter //Refresh DataGrid //Update the DataGrid with the new item picked }}
Try to catch it on KeyPress
private
void txtActivateDG_KeyPress(object sender, KeyPressEventArgs e){
if ((e.KeyChar == '\r')){
//Pressed Enter //Refresh DataGrid //Update the DataGrid with the new item picked}
}
Both options don't get the ENTER key..(And don't ever enter the function at all)
Any ideas?
All other numeric function I get with no problems.
When I have a Focus on a button there is no problem catch the ENTER and the buttom click function stats
Which tells me that the ENTER keypad is OL
When I used the KeyPress I have a different problem that I key somtimes 2-3 Enter together, depanding on the User speed of pressing..and I need to disable the unwanted extra ENTER keys. (Any idea how to that?)
Eran
sorry it's too late, for documentation purposes.
the enter keychar = 13 so the code would be like this.
private void txtActivateDG_KeyPress(object sender, KeyPressEventArgs e) { if (e.KeyChar == 13) { //Pressed Enter //Refresh DataGrid //Update the DataGrid with the new item picked } }if you want to eliminate the unwanted enter keys (for example take 1 enter only if it is pressed multiple times within 2 seconds you will need a class level variable of type DateTime and your code will look like this
DateTime FirstPress = DateTime.Now; private void txtActivateDG_KeyPress(object sender, KeyPressEventArgs e) { if ((e.KeyChar == 13) && (DateTime.Now.Subtract(FirstPress).TotalSeconds > 2)) { FirstPress = DateTime.Now; presses++; //Pressed Enter //Refresh DataGrid //Update the DataGrid with the new item picked } }
这篇关于用于检测ENTER的KeyDown或KeyPress的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!