zoukankan      html  css  js  c++  java
  • C# WebBrowser获取指定字符串的坐标

     以下代码实现WebBrowser获取指定字符串的坐标并将WebBrowser的滚动条定位到该坐标

               public void FindKeyWord(string keyWord)
               {
                   WebBrowser wb = new WebBrowser();
                    foreach (HtmlElement item in wb.Document.All)
                    {
                if (item.InnerText != null) { if (ClearChar(item.InnerText) == keyWord) { Point point = GetPoint(item); wb.Document.Window.ScrollTo(point.X, point.Y);//滚动条至指定位置 break; } } } }
         public Point GetPoint(HtmlElement el)
            {
                Point pos = new Point(el.OffsetRectangle.Left, el.OffsetRectangle.Top);
                //循环获取父级的坐标
                HtmlElement tempEl = el.OffsetParent;
                while (tempEl != null)
                {
                    pos.X += tempEl.OffsetRectangle.Left;
                    pos.Y += tempEl.OffsetRectangle.Top;
                    tempEl = tempEl.OffsetParent;
                }
                return pos;
            }
    
            public string ClearChar(string str)
            {
                str = str.Replace("
    ", null);
                str = str.Replace("
    ", null);
                str = str.Replace(" ", null);
                str = str.Replace(" ", null);
                return str;
            }
  • 相关阅读:
    积累
    AnkhSVN使用记录
    时间戳
    Nhibernate
    Css的sb问题
    ajax
    WAS资料收集
    CryStal资料收集
    Decorator模式
    MSDN WebCast网络广播全部下载列表
  • 原文地址:https://www.cnblogs.com/a849788087/p/6567188.html
Copyright © 2011-2022 走看看