0

关于这篇文章“HtmlElementEventHandler Delegate” http://msdn.microsoft.com/en-us/library/system.windows.forms.htmlelementeventhandler.aspx

上下文菜单事件处理程序多次触发。你如何抑制重复事件的触发?

这是我的代码:

公共事件 DocumentCompleted As WebBrowserDocumentCompletedEventHandler

Private Sub WebBrowser1_DocumentCompleted(sender As Object, e As WebBrowserDocumentCompletedEventArgs) Handles    WebBrowser1.DocumentCompleted
    Dim Doc As HtmlDocument = Me.WebBrowser1.Document
    AddHandler Doc.ContextMenuShowing, New HtmlElementEventHandler(AddressOf Document_ContextMenuShowing)
    Dim htmldoc As HtmlDocument = Me.WebBrowser1.Document
End Sub

Private Sub Document_ContextMenuShowing(ByVal sender As Object, ByVal e As HtmlElementEventArgs)
    Try
        Dim doc As HtmlDocument = CType(sender, HtmlDocument)
        If doc.ActiveElement.TagName = "A" Then
            MsgBox(doc.ActiveElement.InnerHtml)
            e.ReturnValue = False
        End If
    Catch ex As Exception
    End Try
End Sub
4

1 回答 1

1

DocumentCompleted 将为网页中的每个框架触发。在您的 WebBrowser1_DocumentCompleted Sub 中仅使用一次 AddHandler 以使其仅触发一次。

于 2013-02-26T03:27:07.407 回答