按键,按键,按键? [英] Key Press , Key down , key up?
本文介绍了按键,按键,按键?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
您好,
i已经阅读了按键,按键,按键事件,但我无法通过任何代码示例测试它...可能你请帮我一个这个事件的简单代码......?
我尝试过但按Enter键时无法正常工作? :(
Hello ,
i have read the key press, key down , key up event but i couldn''t test it by any code example ... may u help me please for a simple code of this events ...?
i tried it but not working when i press Enter Key? :(
private void textBox1_Keydown(object sender, KeyPressEventArgs e)
{
if (e.KeyChar == (char)Keys.Enter)
{
string s = textBox1.Text;
messagebox.show("Enter is down " + s);
}
}
非常感谢
many thanks
推荐答案
对于KeyDown
事件,你有一个KeyEventArgs
作为参数,而不是KeyPressEventArgs
。
你应该使用KeyPressEventArgs
作为KeyPress
方法的参数。
将参数设置为KeyEventArgs
(或使用KeyDown
事件而不是KeyPress
事件)并尝试这样做:
For aKeyDown
event, you''ve aKeyEventArgs
as a parameter, not aKeyPressEventArgs
.
You should use aKeyPressEventArgs
as a parameter for theKeyPress
method.
Set the parameter to aKeyEventArgs
(or use aKeyDown
event instead of aKeyPress
event) and try this:
private void textBox1_Keydown(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.Up) // or Keys.Down, Keys.Left, Keys.Right
{
// do something...
}
}
希望这会有所帮助。
Hope this helps.
这篇关于按键,按键,按键?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文