.NET WebBrowser控件-获取活动上下文菜单 [英] .NET WebBrowser control - get active contextmenu

查看:128
本文介绍了.NET WebBrowser控件-获取活动上下文菜单的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我具有WebBrowser控件,我希望在单击右键时出现上下文菜单以获取该上下文菜单的句柄.

I have WebBrowser control and i want when right button is clicked and context menu appear to get the handle of that context menu.

有可能吗?

推荐答案

是.

您可以参考以下代码.

    //this code assumes WebBrowser object(_webBrowser) is already initiated
    //in class scope.

    //this method is needed to execute when form is loaded.
    //Register it to load event
    private void Loaded(object sender, RoutedEventArgs e)
    {
        _webBrowser.LoadCompleted += _webBrowser_LoadCompleted;
    }

    private HTMLDocumentEvents2_Event _docEvent;

    private void _webBrowser_LoadCompleted(object sender, NavigationEventArgs e)
    {
        if (_docEvent != null)
        {
            _docEvent.oncontextmenu -= new HTMLDocumentEvents2_oncontextmenuEventHandler(_docEvent_oncontextmenu);
        }
        if (_webBrowser.Document != null)
        {
            _docEvent = (HTMLDocumentEvents2_Event)_webBrowser.Document;
            _docEvent.oncontextmenu += new HTMLDocumentEvents2_oncontextmenuEventHandler(_docEvent_oncontextmenu);
        }
    }

    bool _docEvent_oncontextmenu(IHTMLEventObj pEvtObj)
    {
        //do something and determine you want whether context menu shows or not
        //if you want to shows context menu, you'll need to return true.
        return true;
    }

这篇关于.NET WebBrowser控件-获取活动上下文菜单的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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