1
如何禁用WPF WebBrowser-Control的標準上下文菜單?禁用WebBrowser contextmenu
如何禁用WPF WebBrowser-Control的標準上下文菜單?禁用WebBrowser contextmenu
使用mshtml;
private mshtml.HTMLDocumentEvents2_Event documentEvents;
在構造函數或XAML中設置您的LoadComplete事件:
webBrowser.LoadCompleted += webBrowser_LoadCompleted;
然後在該方法中創建新的web瀏覽器的文檔對象,然後查看可用的屬性,並創建新的事件如下:
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
}
好問題,+ 1up。這可能是有用的http://stackoverflow.com/questions/5507734/disable-context-menu-on-webbrowser-in-wpf – ToddBFisher
可能的重複[如何停用「右鍵點擊」WPF Webbrowser控制?](http: //stackoverflow.com/questions/4412915/how-to-deactivate-right-click-on-wpf-webbrowser-control) –