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

后端 未结 7 1266
萌比男神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:02

    The cleanest way that works for me is the following:

    HtmlElement elem = webBrowser.Document.GetElementById(idElement); IHTMLRect rect = ((IHTMLElement2) elem.DomElement).getBoundingClientRect(); // rect.top and rect.left represent absolute coordinates.

提交回复
热议问题