KeyUp事件 [英] KeyUp events
问题描述
你好,
我正试图通过KeyUp事件抓住左右箭头键
,如下: br />
public Form1()
{
InitializeComponent();
Form1.ActiveForm.KeyUp + = new
KeyEventHandler(ActiveForm_KeyUp);
}
void ActiveForm_KeyUp(对象发送者,KeyEventArgs e)
{
if(e.KeyCode == Keys.Left)
MessageBox.Show(" Left arrow key");
else if(e.KeyCode == Keys.Right)
MessageBox.Show("右箭头键);
}
然而,当我按下按钮时,事件永远不会被调用。我尝试将
事件绑定放在表单加载中,但这也不起作用。
有什么想法吗?
>
谢谢,
Ben
Hello,
I''m trying to catch the pressing of the left and right arrow keys
through the KeyUp event, like so:
public Form1()
{
InitializeComponent();
Form1.ActiveForm.KeyUp += new
KeyEventHandler(ActiveForm_KeyUp);
}
void ActiveForm_KeyUp(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.Left)
MessageBox.Show("Left arrow key");
else if(e.KeyCode == Keys.Right)
MessageBox.Show("Right arrow key");
}
Yet the event is never called when I press a button. I tried putting the
event binding in the form load, but that didn''t work either.
Any ideas?
Thanks,
Ben
推荐答案
" Ben" < el ***** @ gmail.com在消息中写道
news:ud ************** @ TK2MSFTNGP06.phx.gbl ...
"Ben" <el*****@gmail.comwrote in message
news:ud**************@TK2MSFTNGP06.phx.gbl...
您好,
我正试图抓住左右箭头键的按键
KeyUp事件,如下:
public Form1()
{
InitializeComponent();
Form1.ActiveForm.KeyUp + = new
KeyEventHandler(ActiveForm_KeyUp);
}
void ActiveForm_KeyUp(对象发送者,KeyEventArgs e)
{
if(e.KeyCode == Keys.Left)
MessageBox.Show(" left arrow key");
else if(e.KeyCode == Keys.Right)
MessageBox.Show(" Right arrow key");
}
然而,当我按下按钮时,事件永远不会被调用。我尝试将
事件绑定放在表单加载中,但这也不起作用。
有什么想法吗?
Hello,
I''m trying to catch the pressing of the left and right arrow keys through
the KeyUp event, like so:
public Form1()
{
InitializeComponent();
Form1.ActiveForm.KeyUp += new
KeyEventHandler(ActiveForm_KeyUp);
}
void ActiveForm_KeyUp(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.Left)
MessageBox.Show("Left arrow key");
else if(e.KeyCode == Keys.Right)
MessageBox.Show("Right arrow key");
}
Yet the event is never called when I press a button. I tried putting the
event binding in the form load, but that didn''t work either.
Any ideas?
我认为你需要使用e.Keyvalue。
I think you will need to use e.Keyvalue.
>
谢谢,
Ben
>
Thanks,
Ben
先生。 Arnold写道:
Mr. Arnold wrote:
>
" Ben" < el ***** @ gmail.com在消息中写道
news:ud ************** @ TK2MSFTNGP06.phx.gbl ...
>
"Ben" <el*****@gmail.comwrote in message
news:ud**************@TK2MSFTNGP06.phx.gbl...
>您好,
我正试图通过KeyUp事件抓住左右箭头键的按键
,像这样:
public Form1()
{InitialifyComponent();
Form1.ActiveForm.KeyUp + = new
KeyEventHandler(ActiveForm_KeyUp);
}
void ActiveForm_KeyUp(对象发送者,KeyEventArgs e)
{
if(e.KeyCode == Keys.Left)
MessageBox.Show( 左箭头键);
否则if(e.KeyCode == Keys.Right)
MessageBox.Show(" Right arrow key");
}
<但是当我按下按钮时,事件永远不会被调用。我尝试将
事件绑定放在表单加载中,但这也不起作用。
任何想法?
>Hello,
I''m trying to catch the pressing of the left and right arrow keys
through the KeyUp event, like so:
public Form1()
{
InitializeComponent();
Form1.ActiveForm.KeyUp += new
KeyEventHandler(ActiveForm_KeyUp);
}
void ActiveForm_KeyUp(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.Left)
MessageBox.Show("Left arrow key");
else if(e.KeyCode == Keys.Right)
MessageBox.Show("Right arrow key");
}
Yet the event is never called when I press a button. I tried putting
the event binding in the form load, but that didn''t work either.
Any ideas?
我认为你需要使用e.Keyvalue。
I think you will need to use e.Keyvalue.
>> ;
谢谢,
Ben
>>
Thanks,
Ben
这不是问题所在。当它在函数的第一行放置一个
断点时它甚至不会停止执行,这让我相信它甚至不会被调用。 br />
That''s not the problem. It doesn''t even stop executing when putting a
breakpoint on the first line of the function, which leads me to believe
it''s not even called.
可能是事件未达到表格?当你有一个没有任何子控制的空表格时,你会遇到同样的问题吗?
SG
"本" < el ***** @ gmail.com在消息中写道
news:ud ************** @ TK2MSFTNGP06.phx.gbl ...
May be the event is not reaching the form? Do you get the same problem when
you have an empty form without any child controls?
SG
"Ben" <el*****@gmail.comwrote in message
news:ud**************@TK2MSFTNGP06.phx.gbl...
您好,
我正试图抓住左右箭头键的按键
KeyUp事件,如下:
public Form1()
{
InitializeComponent();
Form1.ActiveForm.KeyUp + = new
KeyEventHandler(ActiveForm_KeyUp);
}
void ActiveForm_KeyUp(对象发送者,KeyEventArgs e)
{
if(e.KeyCode == Keys.Left)
MessageBox.Show(" left arrow key");
else if(e.KeyCode == Keys.Right)
MessageBox.Show(" Right arrow key");
}
然而,当我按下按钮时,事件永远不会被调用。我尝试将
事件绑定放在表单加载中,但这也不起作用。
有什么想法吗?
>
谢谢,
Ben
Hello,
I''m trying to catch the pressing of the left and right arrow keys through
the KeyUp event, like so:
public Form1()
{
InitializeComponent();
Form1.ActiveForm.KeyUp += new
KeyEventHandler(ActiveForm_KeyUp);
}
void ActiveForm_KeyUp(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.Left)
MessageBox.Show("Left arrow key");
else if(e.KeyCode == Keys.Right)
MessageBox.Show("Right arrow key");
}
Yet the event is never called when I press a button. I tried putting the
event binding in the form load, but that didn''t work either.
Any ideas?
Thanks,
Ben
这篇关于KeyUp事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!