getting absolute position of HTML element in webbrowser control with C#

后端 未结 7 1262
萌比男神i
萌比男神i 2021-02-04 07:39

I was wondering if its possible to get the absolute position of specific HTML element I have loaded in webbrowser control with C#.

I tried almost all of the options that

7条回答
  •  长发绾君心
    2021-02-04 08:07

    There is a direct way to get the coordinates. IHTMLElement2 has the method getBoundingClientRect that gives you the coordinates of the element.

    IHTMLDocument3 doc = (IHTMLDocument3)this.webbrowser.Document;
    IHTMLElement2 element = (IHTMLElement2)doc.getElementById(idElement);
    IHTMLRect rect = element.getBoundingClientRect();
    
    int x = rect.left;
    int y= rect.top;
    

提交回复
热议问题