1

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

4

1 回答 1

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
}
于 2016-03-28T18:27:34.060 回答