Keyup事件 [英] Keyup event

查看:76
本文介绍了Keyup事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经在C#中创建了一个表单,并且我试图让程序在按下特定按钮时执行某些操作。我做了以下工作:


this.KeyUp + = new System.Windows.Forms.KeyEventHandler(this.POS_KeyU p);


private void POS_KeyUp(object sender,System.Windows.Forms.KeyEventArgs e)

{

if(e.KeyValue.ToString()==" 123")< br $>
{

Update1.PerformClick();

}

System.Windows.Forms.MessageBox.Show(e .KeyValue.To String());

}


然而这不起作用。我甚至没有收到消息框。任何人都可以帮忙吗?

Hi, I''ve created a form in C# and I am trying to get the program to do something when a particular button is pressed. I have done the following:

this.KeyUp += new System.Windows.Forms.KeyEventHandler(this.POS_KeyU p);

private void POS_KeyUp(object sender, System.Windows.Forms.KeyEventArgs e)
{
if(e.KeyValue.ToString()=="123")
{
Update1.PerformClick();
}
System.Windows.Forms.MessageBox.Show(e.KeyValue.To String());
}

this however does not work. I don''t even get a message box. Can anyone help?

推荐答案

" 123"不是键盘上的键,至少不是我见过的任何键。

该事件用于捕获单个按键。您可以在此基础上跟踪一系列按键,但不能同时跟踪所有按键。


您的表单必须关注该事件才能触发。当你松开按钮时会触发,而不是按下它的按下
"123" is NOT a key on a keyboard, at least not on any I''ve seen.
That event is used to capture individual key presses. You can build upon that to track a sequence of keypresses, but not all at once.

Your form has to have the focus for that event to fire. And it will fire when you release the button, not on it''s press


123是F12


此外我的表格确实有焦点即使我松开按钮也没有任何反应。我试过按其他按钮但消息框甚至没有出现
123 is F12

Also my form does have the focus and nothing happens, even when I release the button. I''ve tried pressing other buttons but the messagebox doesn''t even come up



123是F12


此外,我的表格确实有焦点,没有任何反应,即使我释放按钮。我试过按其他按钮但消息框甚至没有出现
123 is F12

Also my form does have the focus and nothing happens, even when I release the button. I''ve tried pressing other buttons but the messagebox doesn''t even come up



你在哪里输入这段代码?

where are u entering this piece of code?

展开 | 选择 | Wrap | 行号


这篇关于Keyup事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆