Path Bounded Text

Drawing Text Layout

Draws text that flows across text frames; a green ellipse serves as a wrapping path that excludes text from its area.

Сode Snippet

using (var bitmap = new Bitmap(600, 300, PixelFormat.Format24bppRgb, RgbColor.White))
using (var graphics = bitmap.GetAdvancedGraphics())
{
    var dummyText = @"Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do " +
        "eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim " +
        "veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo " +
        "consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum " +
        "dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, " +
        "sunt in culpa qui officia deserunt mollit anim id est laborum.";

    var pathBoundedText = new PathBoundedText(dummyText, graphics.CreateFont("Verdana", 18f), new SolidBrush(RgbColor.Black));

    // Adding text areas. When the first text area runs out of space,
    // text will automatically flow to the next one.
    var boundingPath1 = new Path();
    boundingPath1.DrawRectangle(20, 20, 260, 260);
    pathBoundedText.BoundingPaths.Add(boundingPath1);

    var boundingPath2 = new Path();
    boundingPath2.DrawRectangle(320, 20, 260, 260);
    pathBoundedText.BoundingPaths.Add(boundingPath2);

    // Adding paths which you need to wrap with the text
    var wrappingPath = new Path();
    wrappingPath.DrawEllipse(200, 100, 200, 100);
    pathBoundedText.WrappingPaths.Add(wrappingPath);

    graphics.DrawText(pathBoundedText);

    // Drawing frames around text blocks (for demonstration purposes)
    graphics.FillPath(new SolidBrush(RgbColor.LightGreen), wrappingPath);

    var pen = new Pen(RgbColor.Red);
    graphics.DrawPath(pen, boundingPath1);
    graphics.DrawPath(pen, boundingPath2);

    graphics.DrawLine(new Pen(RgbColor.Blue, 2f), 280f, 280f, 320f, 20f);

    bitmap.Save("DrawPathBoundedText.png");
}

Output

DrawPathBoundedText.png

For AI-assisted development: Download Graphics Mill Code Samples XML Catalog