This project is read-only.

Get the screen location of one element

Aug 4, 2014 at 4:47 PM
For my application, it is very important the calculate the the location of each CssBox.

I followed the instruction at:

I tried to change the internal class to public so that I can call from outside application.

However, no matter what i did, the location data I got from rectangle is always 0, x=0, y=0, everything =0. Please let me know how do I obtain the Height/Width, X, Y of each CssBox.

My code as below.
    public void Execute(Webpage page)
        HtmlRenderer.HtmlContainer hc = new HtmlRenderer.HtmlContainer();
        hc.SetHtml(page.Source, null);
        InsertTag(hc.Root, 0, 0);

    private void InsertTag(CssBox box, int parenttagid, int siblingindex)
        string tagname = string.Empty;

        if (box.HtmlTag != null)
           tagname= box.HtmlTag.Name;

        var rect = box.Rectangles;       /// all 0
        var bounds = box.Bounds;      /// all 0
        var clientrect = box.ClientRectangle;    /// all 0

        var myownrect = box.GetElementRectangle();  //copy code from HtmlContainer. 

        // dosomething here.

        foreach (var item in box.Boxes)
            InsertTag(item, parenttagid, 0);
Aug 5, 2014 at 1:53 PM
I would strongly recommend not to expose CssBox or to manipulate its internals from outside, it will probably not do what you want.
in your case you didn't call layout so none of the elements are in place.