HtmlDocument.ContextMenuShowing Event

Definition

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

C#
public event System.Windows.Forms.HtmlElementEventHandler ContextMenuShowing;
C#
public event System.Windows.Forms.HtmlElementEventHandler? ContextMenuShowing;

Event Type

Examples

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

C#
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)
{
    menuStrip.Show(e.MousePosition);
    e.ReturnValue = false;
}

Remarks

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.

Applies to

Product Versions
.NET Framework 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
Windows Desktop 3.0, 3.1, 5, 6, 7, 8, 9, 10

See also