Notifications
Clear all

[Closed] How to detect an element mouse event in webbrowser ?

Hi,
I am trying to capture an element mouse event in webbrowser,there is an example of C#,but I don’t know how to make it in maxscript.
https://stackoverflow.com/questions/14933979/how-to-capture-click-event-for-any-button-inside-in-web-browser-control

WebBrowser _browser;
this._browser.DocumentCompleted+=new WebBrowserDocumentCompletedEventHandler(browser_DocumentCompleted);
...
private void browser_DocumentCompleted(Object sender, WebBrowserDocumentCompletedEventArgs e)
{
    this._browser.Document.Body.MouseDown += new HtmlElementEventHandler(Body_MouseDown);
}
...
void Body_MouseDown(Object sender, HtmlElementEventArgs e)
{
    switch(e.MouseButtonsPressed)
    {
    case MouseButtons.Left:
        HtmlElement element = this._browser.Document.GetElementFromPoint(e.ClientMousePosition);
        if(element != null && "submit".Equals(element.GetAttribute("type"),StringComparison.OrdinalIgnoreCase)
        {
        }
    break;
    }
}

For example,if there is an element names “FORUMS”,how can I check when a mouse pressing it?

rollout test ""
(
   dotNetControl w_b "System.Windows.forms.WebBrowser" pos:[0,0] width:620 height:460   
   on test open do
   (
      w_b.ScriptErrorsSuppressed=true
      w_b.url=dotNetObject "System.Uri" ("http://forums.cgsociety.org/forumdisplay.php?f=6")
   )   
   on w_b DocumentCompleted arg do 
   (
      get_forum_element_id=w_wb.Document.GetElementById "FORUMS"  --If there is an element names "FORUMS",then I want to detect element "FORUMS" mouse event when mouse pressing it
   )
   
)
createDialog test 640 480
4 Replies

I can’t see almost any difference in mxs/c# way of doing it.

rollout test ""
(
    dotNetControl w_b "System.Windows.forms.WebBrowser" pos:[0,0] width:620 height:460
   
    local clickHandlerAttached = false        
    
    fn dnMouseDown sender ev = (

        if ev.MouseButtonsPressed == (dotNetClass "System.Windows.Forms.MouseButtons").Left do (
            
            local element = w_b.Document.GetElementFromPoint ev.ClientMousePosition
            
            format "MouseDown. Element:% Tag:<%>
" element.InnerText element.TagName

        )
        
    )
    
    fn attachClickHandler sender ev = (
        
        dotNet.addEventHandler w_b.Document.Body "MouseDown" dnMouseDown
        format "Click handler attached.
" 
        
    )
    
    on test open do
   (
      w_b.ScriptErrorsSuppressed = true       
       
      w_b.url = dotNetObject "System.Uri" ("http://forums.cgsociety.org/forumdisplay.php?f=6")
    
   )
   
   
   on w_b DocumentCompleted arg do
   (
       if not clickHandlerAttached and w_b.Document.Body != undefined do (

            clickHandlerAttached = true
            dotNet.addEventHandler w_b.Document.Window "load" attachClickHandler
       )
   )
     

)
createDialog test 640 480


        if ev.MouseButtonsPressed == ev.MouseButtonsPressed.Left do (

it doesn’t create a new instance of mxs .net value

yes, that’s much better

1 Reply
(@momo2012)
Joined: 11 months ago

Posts: 0

Works like a charm,thanks for great help,Serejah and denisT