locked
Webbrowser - What to use Invokemember or raiseevent or firevent to trigger onmouseover on an htmlelement

    Question

  • Hi All,

    I have and webbrowser control over my form , where i had the object of one of the htmlelement.

    objhtml.InnerHtml is "<DIV onmouseover="page.hist(this,'P-0.00--0',47114826,14,event,0,1)" onmouseout=delayHideTip()>4.41</DIV>"

    How can i trigger the onmouseover event. I need this , because on mouse over the elelement, displays a tooltip, which i need to reed.

    Tried invokememeber, Raiseevent and fireevent nothing worked.

    Also tried programtically to move the cursor over the element, achieved it , but it is not allowing me to do any other work , when i run my code.

    Kindly help me in this.

    Thanks in advance




    • Edited by Naren901 Saturday, July 28, 2012 4:48 PM
    Saturday, July 28, 2012 3:16 PM

Answers

All replies

  • Hi Naren,

    Welcome to the MSDN forum.

    According to your description, you need to call Javascript in VB.NET. If so, I think you can use WebBrowser.Documents.InvokeScript to invoke this script method. More information about VB.NET/C# and JavaScript communication.

    If I misunderstood anything, please feel free to let me know.

    Best regards,


    Shanks Zen
    MSDN Community Support | Feedback to us

    Monday, July 30, 2012 9:16 AM
    Moderator
  • Thanks Shanks,

    Invoke script needs arguments here onmouseover="page.hist(this,'P-0.00--0',47114826,14,event,0,1)"

    How can i send event object. Which is definetely a mouseover event of object type IHTMLEventObj 

    http://www.oddsportal.com/soccer/spain/primera-division-2011-2012/malaga-santander-827196/

    Hover the mouse over the table cell in the above link, thats the value i want to trigger, So i feel the event argument i can only get by triggering the mouseonover event.

    Other ways i tried which dint work:

    objhtmlElement.InnerHtml = Replace(objhtmlElement.InnerHtml, "onmouseout=delayHideTip()", "") 'Which does not trigger the other event even my mouse is outside

    Attempt 1: 

    Form1.WebBrowser1.Document.InvokeScript("page.hist(this,'P-0.00--0',47114826,14,event,0,1)")

    Attempt 2: "Click" works, but not "onmouseover"

                objhtmlElement.InvokeMember("onmouseover")
                'or
                objhtmlElement.InvokeMember("mouseover")

    Attempt 3:

    objhtmlElement.RaiseEvent("onmouseover")

    Attempt 4: 

    'FInally tried from Domobject. Not pretty sure whether i wrote it right, but still it dint worked.

    Dim doc As IHTMLDocument4
            doc = DirectCast(WebBrowser1.Document.DomDocument, IHTMLDocument4)
            Dim dummy As Object = Nothing
            Dim eventObj As IHTMLEventObj = doc.CreateEventObject(dummy)
            Dim el As mshtml.IHTMLElement3
            el = DirectCast(objhtmlElement.DomElement, mshtml.IHTMLElement3)

            Dim btemp As Boolean = el.FireEvent("onmouseover", eventObj)

    Attmpt 5: The crude way worked, but i dont like my mouse to freeze when it trying for 1000 of pages to fetch values.

    objhtmlElement is the object of cell in the table

    'Moves the element in view (top left)

    objhtmlElement.ScrollIntoView(True)

    ' Get the position of the element in the form - then move my cursor over to the place

    Dim objPoint As New System.Drawing.Point(Form1.Left + Form1.WebBrowser1.Left + (objhtmlElement.ScrollRectangle.Width / 2) , Form1.Top + (Form1.Height - Form1.ClientSize.Height) + Form1.WebBrowser1.Top + (objhtmlElement.ScrollRectangle.Height / 2))

     Cursor.Position = objPoint   'Which exactly moves my cursor over the element(freezes my mouse when trying to run my app for n number of cells)

    So these are my problems, Any suggestions , it will be greatly helpful.

    Thanks in advance.

    Monday, July 30, 2012 6:46 PM
  • Hello,

    I come up with a possible solution, but Im not sure if this works. First you need to create a javascript function for simulating mouse over and then inject this code into web page, then call this method.

    http://pastebin.com/5j84cbm2

    http://stackoverflow.com/questions/153748/how-to-inject-javascript-in-webbrowser-control

    Hope this helps.


    Think again!

    Tuesday, July 31, 2012 2:34 AM