HtmlDocument.ContextMenuShowing Event


Occurs when the user requests to display the document's context menu.

Namespace:   System.Windows.Forms
Assembly:  System.Windows.Forms (in System.Windows.Forms.dll)

public event HtmlElementEventHandler ContextMenuShowing

By default, if you right-click your mouse on a document or an element in a document, it will display a default context menu particular to the element. Use this event to cancel the display of the context menu and display one of your own.

The following code example captures the ContextMenuShowing event and uses it to display a ContextMenuStrip.

ContextMenuStrip menuStrip = null;

public void DetectContextMenu()
    if (webBrowser1.Document != null)
        webBrowser1.Document.ContextMenuShowing += new HtmlElementEventHandler(Document_ContextMenuShowing);
        menuStrip = new ContextMenuStrip();
        menuStrip.Items.Add("&Custom menu item...");

void Document_ContextMenuShowing(object sender, HtmlElementEventArgs e)
    e.ReturnValue = false;

.NET Framework
Available since 2.0
Return to top