Absolute position of Elements within a web browser activex control

  • Thread starter Thread starter chris
  • Start date Start date
C

chris

I'm using the code below to attempt to find out the absolute pixel
position of an element inside an activex web browser control
(axWebBrowser).

This example uses the 'www.google.co.uk' web page and attempts to find
the position of the editbox where the search critera is enetered.

My problem I'm having is that the result is always near the element but
never exact (in this case, the left co-ordinate seems to be 7 pixels to
high).

IHTMLDocument3 Doc = (IHTMLDocument3)axWebBrowser.Document;
IHTMLElementCollection Elements = Doc.getElementsByName("q");

int lL = 0;
int lT = 0;
IHTMLElement El2 = ((IHTMLElement)Element);
while (El2.parentElement != null)
{
if (El2.tagName != "FORM")
{
lL += El2.offsetLeft;
lT += El2.offsetTop;
}
El2 = El2.parentElement;
}

Rectangle Absolute =
axWebBrowser.RectangleToScreen(axWebBrowser.ClientRectangle);
Cursor.Position = new Point(lL+Absolute.Left, lT+Absolute.Top);

Any Ideas?

Thanks in advance
Chris.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top