WHen we click on site whether left click or right....Control goes to IEDoc_MouseDown event,I just want to ask is that possible to know taht which element is clicked..Suppose we right click on link,is that possible to know it that link is clicked.

Public Class Form2
    Dim WithEvents IEDoc As System.Windows.Forms.HtmlDocument
    Private Sub Form2_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        WebBrowser1.Navigate("www.google.com")
        If WebBrowser1.IsWebBrowserContextMenuEnabled Then
            WebBrowser1.IsWebBrowserContextMenuEnabled = False
        End If
    End Sub

    Private Sub WEB_DocumentCompleted(ByVal sender As System.Object, ByVal e As System.Windows.Forms.WebBrowserDocumentCompletedEventArgs) Handles WebBrowser1.DocumentCompleted
        Try
            IEDoc = WebBrowser1.Document
            
        Catch ex As Exception
            MsgBox(ex.Message)
        End Try
    End Sub

    Private Sub IEDoc_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.HtmlElementEventArgs) Handles IEDoc.MouseDown
        If e.MouseButtonsPressed = Windows.Forms.MouseButtons.Right Then
            MsgBox("sonia")
        End If
    End Sub

End Class

PLZ let me know...Very Urgent

Hi Sonia,

I Suggest using the ContextMenuShowing instead of MouseDown , as it seems that MouseDown is 1 click behind and don't give the current element but it gives the previous element that rightclick is occur on it.

Now, to get the element (I don't know what information you want) info, just put a debug point as I post in my example below and search under Sender.ActiveElement Replace the mouse down event with this.

Sub IEDoc_ContextMenuShowing(ByVal sender As Object, ByVal e As System.Windows.Forms.HtmlElementEventArgs) Handles IEDoc.ContextMenuShowing
    Dim ElementInfo = sender.ActiveElement.ID + vbTab + sender.ActiveElement.InnerHTML ' <-- Put debug point here and add sender to the watch window and search under activeelement
    Debug.Print(ElementInfo)
End Sub

Hey frnd i have test this code on many sites...WHen we click on any hypelink
then in ElementInfo "A" is coming.....

Sub IEDoc_ContextMenuShowing(ByVal sender As Object, ByVal e As System.Windows.Forms.HtmlElementEventArgs) Handles IEDoc.ContextMenuShowing

Dim ElementInfo As String = sender.ActiveElement.tagname
MsgBox(ElementInfo)

End Sub

Thx very much...Can u plz tell me i m gng in d right way.....

sender.ActiveElement.tagname

That Will return the HTML Tag name such as "A" "BODY" "INPUT" etc...

Thx very much...Can u plz tell me i m gng in d right way.....

Just follow the sign road and compare it with your map :)

What you are trying to do with your code?

ACtually sir i disable the IE contextManus....& i want to attach mine own context menus..I want that when the user right click on any link contextmenu1 is there..& else contextmenu2 is there...
SO for all the links HTML Tag name will return "A" ...I tested in almost every sites.....So i attach contectmenu1.....I just want to ask that i m doing the right code na!!!!!!!!

Just one question,

Is you sonia sardana and ritu verma are the same person?

I ask Sonia and you response, please clarify?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.