簡體   English   中英

禁用WebBrowser上下文菜單

[英]Disable WebBrowser contextmenu

如何禁用WPF WebBrowser-Control的standard-context菜單?

使用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
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM