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

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

问题描述

我现在用的是 web浏览器在C#应用程序控制,并希望处理所有按键事件,而 web浏览器有的焦点,无论什么各个内容要素(输入字段,链接等)被​​聚焦。我试图只是一个事件处理程序添加到浏览器控件的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?

推荐答案

您的<一个href=\"http://msdn.microsoft.com/en-us/library/system.windows.forms.control.$p$pviewkeydown.aspx\">$p$pviewKeyDown事件只是把它挂起来。

you have the PreviewKeyDown event just hook it up.

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天全站免登陆