With a 200px-width rectangle, and a 12pt font, it requires six lines to display the string in its entirety

image_pdfimage_print
   
 
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

public class Form1 : Form {

    protected override void OnPaint(PaintEventArgs e) {
    Graphics g = e.Graphics;
    g.FillRectangle(Brushes.White, this.ClientRectangle);

    String s = "This string is long enough to wrap. ";
    Font f = new Font("Arial", 12);
    Rectangle r = new Rectangle(20, 20, 200, f.Height * 6);

    g.DrawRectangle(Pens.Black, r);
    g.DrawString(s, f, Brushes.Black, r);

    f.Dispose();
    }
    public static void Main() {
        Application.Run(new Form1());
    }
}

    


This entry was posted in 2D Graphics. Bookmark the permalink.