Aspose.Words.Examples.CSharp.Rendering_and_Printing.OutlineLayoutEntitiesRenderer.AddBoundingBoxToElementsOnPage C# (CSharp) Méthode

AddBoundingBoxToElementsOnPage() private static méthode

Adds a colored border around each layout element on the page.
private static AddBoundingBoxToElementsOnPage ( LayoutEnumerator it, Graphics g ) : void
it LayoutEnumerator
g System.Drawing.Graphics
Résultat void
        private static void AddBoundingBoxToElementsOnPage(LayoutEnumerator it, Graphics g)
        {
            do
            {
                // This time instead of MoveFirstChild and MoveNext, we use MoveLastChild and MovePrevious to enumerate from last to first.
                // Enumeration is done backward so the lines of child entities are drawn first and don't overlap the lines of the parent.
                if (it.MoveLastChild())
                {
                    AddBoundingBoxToElementsOnPage(it, g);
                    it.MoveParent();
                }

                // Convert the rectangle representing the position of the layout entity on the page from points to pixels.
                RectangleF rectF = it.Rectangle;
                Rectangle rect = new Rectangle(PointToPixel(rectF.Left, g.DpiX), PointToPixel(rectF.Top, g.DpiY),
                    PointToPixel(rectF.Width, g.DpiX), PointToPixel(rectF.Height, g.DpiY));

                // Draw a line around the layout entity on the page.
                g.DrawRectangle(GetColoredPenFromType(it.Type), rect);

                // Stop after all elements on the page have been procesed.
                if (it.Type == LayoutEntityType.Page)
                    return;

            } while (it.MovePrevious());
        }