HtmlDocument.ContextMenuShowing 事件

定义

当用户请求显示文档的上下文菜单时发生。

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 

事件类型

示例

下面的代码示例捕获 事件并 ContextMenuShowing 使用它来显示 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;
}

注解

默认情况下,如果右键单击文档或文档中的元素上的鼠标,则会显示特定于 该元素的默认上下文菜单。 使用此事件可取消上下文菜单的显示,并显示自己的菜单之一。

适用于

另请参阅