Я использую эти функции c # для определения позиций элементов. Вам необходимо передать ссылку на рассматриваемый элемент HTML.
public static int findPosX( mshtml.IHTMLElement obj )
{
int curleft = 0;
if (obj.offsetParent != null )
{
while (obj.offsetParent != null )
{
curleft += obj.offsetLeft;
obj = obj.offsetParent;
}
}
return curleft;
}
public static int findPosY( mshtml.IHTMLElement obj )
{
int curtop = 0;
if (obj.offsetParent != null )
{
while (obj.offsetParent != null )
{
curtop += obj.offsetTop;
obj = obj.offsetParent;
}
}
return curtop;
}
Я получаю элементы HTML из текущего документа следующим образом:
// start an instance of IE
public SHDocVw.InternetExplorerClass ie;
ie = new SHDocVw.InternetExplorerClass();
ie.Visible = true;
// Load a url
Object Flags = null, TargetFrameName = null, PostData = null, Headers = null;
ie.Navigate( url, ref Flags, ref TargetFrameName, ref PostData, ref Headers );
while( ie.Busy )
{
Thread.Sleep( 500 );
}
// get an element from the loaded document
mshtml.HTMLDocumentClass document = ((mshtml.HTMLDocumentClass)ie.Document);
document.getElementById("myelementsid");