【问题标题】:Disable WebBrowser contextmenu禁用 WebBrowser 上下文菜单
【发布时间】:2012-06-07 18:53:59
【问题描述】:

如何禁用 WPF WebBrowser-Control 的标准上下文菜单?

【问题讨论】:

标签: c# .net wpf webbrowser-control


【解决方案1】:

使用 mshtml;

    private mshtml.HTMLDocumentEvents2_Event documentEvents;

在构造函数或 xaml 中设置您的 LoadComplete 事件:

   webBrowser.LoadCompleted += webBrowser_LoadCompleted;

然后在该方法中创建新的 webbrowser 文档对象并查看可用属性并创建新事件,如下所示:

private void webBrowser_LoadCompleted(object sender, NavigationEventArgs e)
{
    documentEvents = (HTMLDocumentEvents2_Event)webBrowserChat.Document; // this will access the events properties as needed
    documentEvents.oncontextmenu += webBrowserChat_ContextMenuOpening;
}

private bool webBrowserChat_ContextMenuOpening(IHTMLEventObj pEvtObj)
{
    return false; // ContextMenu wont open
    // return true;  ContextMenu will open
    // Here you can create your custom contextmenu or whatever you want
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2023-03-15
    • 1970-01-01
    • 1970-01-01
    • 2013-05-24
    • 2021-09-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多