处理WebBrowser控件上的关键事件 [英] Handling key events on WebBrowser control

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

问题描述

我在C#应用程序中使用 WebBrowser 控件,并希望处理所有关键事件,而 WebBrowser 具有焦点,不管个别内容元素(输入字段,链接等)如何集中。我试图在浏览器控件 KeyDown 事件中添加一个事件处理程序,但这不起作用。我不想明确地将一个处理程序挂钩到每个可重点的 HtmlElement

I am using the WebBrowser control in a C# application and want to handle all key events while the WebBrowser has the focus, regardless what individual content element (input field, link, etc.) is focused. I tried to simply add an event handler to browser controls KeyDown event, but this does not work. I don't want to explicitly hook a handler to each focusable HtmlElement.

我如何收到所有的关键事件他们被传递给浏览器或其内容元素?

How can I receive all key events before they are passed to the browser or its content elements?

推荐答案

你有 PreviewKeyDown 事件只是挂起来。

private void wb_PreviewKeyDown(object sender, PreviewKeyDownEventArgs e)
{
    // your code handling the keys here, like:
    if (e.Control && e.KeyCode == Keys.C)
    {
        // Do something funny!
    }
}

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

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