簡體   English   中英

攔截IE上下文菜單單擊WebBrowser控件

[英]Intercept IE Context Menu Click in WebBrowser Control

我正在使用WinForms,我已經添加了一個WebBrowser控件,並希望能夠攔截IE瀏覽器的上下文菜單觸發事件,因為瀏覽器控件是IE的一個實例。

我的意思是,我想攔截右鍵單擊菜單項單擊它自己的瀏覽器,我說我自己,因為它是一個IE實例,它在我的應用程序內,必須有一種方法來做到這一點。

我試着看看瀏覽器控件的事件,但沒有任何東西可以幫助我。

謝謝。

以下是取消WebBrowser上下文菜單的示例。 這將有助於您繼續前進:

// wb = WebBrowser control instance name
// attach to the DocumentCompleted event
wb.DocumentCompleted += new WebBrowserDocumentCompletedEventHandler(wb_DocumentCompleted);

void wb_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
{
    // when the document loading is completed, attach to the document context showing event
    wb.Document.ContextMenuShowing += new HtmlElementEventHandler(Document_ContextMenuShowing);
}

void Document_ContextMenuShowing(object sender, HtmlElementEventArgs e)
{
    // cancel showing context menu
    e.ReturnValue = false;
    // take a look at the 'e' parameter for everything else, you can get various information out of it
}

設置webbrowser控件的以下簡單屬性

wbBrowser.IsWebBrowserContextMenuEnabled = false;

暫無
暫無

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

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