Edit

Share via


HtmlDocument.ContextMenuShowing Event

Definition

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

public:
 event System::Windows::Forms::HtmlElementEventHandler ^ ContextMenuShowing;
public event System.Windows.Forms.HtmlElementEventHandler ContextMenuShowing;
public event System.Windows.Forms.HtmlElementEventHandler? ContextMenuShowing;
member this.ContextMenuShowing : System.Windows.Forms.HtmlElementEventHandler 
Public Custom Event ContextMenuShowing As HtmlElementEventHandler 

Event Type

Examples

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)
{
    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

See also