四联光电智能照明论坛

 找回密码
 立即注册
搜索
热搜: 活动 交友 discuz
查看: 1755|回复: 0
打印 上一主题 下一主题

获取webbrowser的HtmlElement元素的位置

[复制链接]
  • TA的每日心情
    开心
    2022-6-10 09:59
  • 366

    主题

    741

    帖子

    9649

    积分

    超级版主

    Rank: 8Rank: 8

    积分
    9649
    跳转到指定楼层
    楼主
    发表于 2016-11-4 16:41:49 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
    public Point GetOffset(HtmlElement el)
    {
        //get element pos
        Point pos = new Point(el.OffsetRectangle.Left, el.OffsetRectangle.Top);

        //get the parents pos
        HtmlElement tempEl = el.OffsetParent;
        while (tempEl != null)
        {
            pos.X += tempEl.OffsetRectangle.Left;
            pos.Y += tempEl.OffsetRectangle.Top;
            tempEl = tempEl.OffsetParent;
        }

        return pos;
    }

    var point = GetOffset(element);
    var x = point.X;
    var y = point.Y;
    您需要登录后才可以回帖 登录 | 立即注册

    本版积分规则

    QQ|Archiver|手机版|小黑屋|Silian Lighting+ ( 蜀ICP备14004521号-1 )

    GMT+8, 2024-5-6 20:51 , Processed in 1.078125 second(s), 23 queries .

    Powered by Discuz! X3.2

    © 2001-2013 Comsenz Inc.

    快速回复 返回顶部 返回列表