捕捉KeyUp事件上的WinForm C# [英] Catch KeyUp Event on WinForm C#

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

问题描述

我试图赶在F5 System.Windows.Forms的为我写的:

I attempt to catch F5 on System.Windows.Forms for that I wrote:

partial class MainForm
{
   (...)
   this.KeyUp += new System.Windows.Forms.KeyEventHandler(this.MainForm_KeyUp);
   (...)
}

public partial class MainForm : Form
{
    (...)

    private void MainForm_KeyUp(object sender, KeyEventArgs e)
    {
        Log("MainForm_KeyUp");
        if (e.KeyCode == Keys.F5)
        {
            RefreshStuff();
        }
    }
}



但我的事件捕获长相并不工作。

But my event catching looks not working.

你知道如何cactch EventKey在 System.Windows.Forms的

Do you know how to cactch EventKey on System.Windows.Forms ?

推荐答案

形式的KeyPreview属性必须设置为true

the keypreview property of the form must be set to true

在此属性设置为true,形式将接收所有的KeyPress,
的KeyDown,和KeyUp事件。经过窗体的事件处理程序已经
完成处理的按键,键击,然后分配到
与焦点的控件。

When this property is set to true, the form will receive all KeyPress, KeyDown, and KeyUp events. After the form's event handlers have completed processing the keystroke, the keystroke is then assigned to the control with focus.

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

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