web浏览器的快捷键 [英] WebBrowser keyboard shortcuts

查看:184
本文介绍了web浏览器的快捷键的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个WebBrowser控件显示一些HTML。
我希望用户能够复制整个文档,但不能做任何事情。

我已经设置了 IsWebBrowserContextMenuEnabled WebBrowserShortcutsEnabled 属性,我想处理的KeyUp 和运行一些code,当用户presses按Ctrl + C。

我怎么能这样做?
WebBrowser控件不支持键盘事件。
我试着用表格的的KeyUp 事件键preVIEW ,但没有开枪的。

修改:这是我的解决方案,灵感来自Jerb的答案

 类CopyableWebBrowser:web浏览器{
    公众覆盖布尔preProcessMessage(参考消息MSG){
        如果(msg.Msg == 0x101 // WM_KEYUP
         &功放;&安培; msg.WParam.ToInt32()==(int)的Keys.C&安培;&安培; ModifierKeys == Keys.Control){
            DoCopy();
            返回true;
        }
        返回基地preProcessMessage(REF MSG)。
    }
    无效DoCopy(){
        Document.ExecCommand(全选,假,空);
        Document.ExecCommand(复制,假,空);
        Document.ExecCommand(取消选择,假,空);
    }
}
 

解决方案

您可以试试这个方法好。把它放在你的主窗体区域,它应该捕获所有的键盘命令。我用它来添加键盘快捷键来动态创建的标签。

 保护覆盖布尔ProcessCmdKey(参考消息味精,钥匙KEYDATA){
    开关(KEYDATA)
    {
        案例Keys.Control | Keys.Tab:
            NextTab();
            返回true;
        案例Keys.Control | Keys.Shift | Keys.Tab:
            previousTab();
            返回true;
        案例Keys.Control | Keys.N:
            创建连接(空);
            返回true;
    }
    返回false;
 

I have a WebBrowser control displaying some HTML.
I want the user to be able to copy the entire document, but not do anything else.

I've set the IsWebBrowserContextMenuEnabled and WebBrowserShortcutsEnabled properties to false, and I want to handle KeyUp and run some code when the user presses Ctrl+C.

How can I do that?
The WebBrowser control doesn't support keyboard events.
I tried using the form's KeyUp event with KeyPreview, but it didn't fire at all.

EDIT: Here's my solution, inspired by Jerb's answer.

class CopyableWebBrowser : WebBrowser {
    public override bool PreProcessMessage(ref Message msg) {
        if (msg.Msg == 0x101    //WM_KEYUP
         && msg.WParam.ToInt32() == (int)Keys.C && ModifierKeys == Keys.Control) {
            DoCopy();
            return true;
        }
        return base.PreProcessMessage(ref msg);
    }
    void DoCopy() {
        Document.ExecCommand("SelectAll", false, null);
        Document.ExecCommand("Copy", false, null);
        Document.ExecCommand("Unselect", false, null);
    }
}

解决方案

You could try this method as well. Put it in your main form area and it should catch all of the keyboard commands. I use it to add keyboard shortcuts to dynamically created tabs.

protected override bool ProcessCmdKey(ref Message msg, Keys keyData) {
    switch (keyData)
    {
        case Keys.Control|Keys.Tab:
            NextTab();
            return true;
        case Keys.Control|Keys.Shift|Keys.Tab:
            PreviousTab();
            return true;
        case Keys.Control|Keys.N:
            CreateConnection(null);
            return true;
    }
    return false;

这篇关于web浏览器的快捷键的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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