开发者

KeyPress\Up\Down doesn't work - C#

开发者 https://www.devze.com 2023-04-12 07:37 出处:网络
I have this code: private void Form1_KeyDown(object sender, KeyEventArgs e) { MessageBox.Show(\"Fail!\");

I have this code:

private void Form1_KeyDown(object sender, KeyEventArgs e)
{
    MessageBox.Show("Fail!");
}

And I've set the event in the Form - but it simply isn't activated.

Other events like Resize or MouseDown work well, only this doesn't work.

Did someone ever experience this problem? What can I do ? [NO button works, neither characters or numerical or whatever]开发者_开发知识库.

Thanks, Mark!


Dis you set theForm1.KeyPreview = true for more info visit http://msdn.microsoft.com/en-us/library/system.windows.forms.form.keypreview%28v=VS.80%29.aspx


i think you have set like this..

 KeyPreview property set to true

and try this.....

int _i = 0;
private void Form1_KeyDown(object sender, KeyEventArgs e) {
    if (e.KeyCode == Keys.Escape) {
        label1.Text = (++_i).ToString();
    }
}
0

精彩评论

暂无评论...
验证码 换一张
取 消