我使用MSHTML DLL开发一个帮手即 我试图得到一个htmll元素的位置, 我有类型HTMLAnchorElementClass的目的 当我试图让他style.posTop值我得到一个空裁判例外

有没有更好的办法做到这一点?

也许其它铸造?

请帮助

有帮助吗?

解决方案

这是我发现的(你获得你的元素对象的引用的方式可能是不同的,但看看这个反正一个例子:

Element = <however your get your element>;

//--- Determine real element size and position relative to the main page.
int ElementLeft = Element.offsetLeft;
int ElementTop = Element.offsetTop;
mshtml.IHTMLElement TmpElem = Element.offsetParent;
while (TmpElem != null)
{
     ElementLeft = ElementLeft + TmpElem.offsetLeft;
     ElementTop = ElementTop + TmpElem.offsetTop;
     TmpElem = TmpElem.offsetParent;
}

其他提示

尝试

element.offsetTop
element.offsetLeft

这个方法不能与此链接 http://s1.webstarts.com/工作VacationHome / rates.html 。 利用项目 点击 高发季节:

在绝对顶部是526 并与项目: $ 160 / NT或£95 / NT 点击 绝对顶部是545。 的距离顺便说一句它们太大

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top