Draw multiline text: auto wrap
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
public class Form1 : System.Windows.Forms.Form{
public Form1()
{
InitializeComponent();
SetStyle(ControlStyles.Opaque, true);
Bounds = new Rectangle(0, 0, 500, 300);
}
protected override void OnPaint(PaintEventArgs e) {
Graphics g = e.Graphics;
g.FillRectangle(Brushes.White, ClientRectangle);
// Draw multiline text
Font trFont = new Font("Times New Roman", 12);
Rectangle rect = new Rectangle(0, 0, 400, trFont.Height * 3);
g.DrawRectangle(Pens.Blue, rect);
String longString = "Text Text Text Text Text Text Text Text Text Text ";
longString += "Text Text Text Text Text Text Text Text Text Text ";
longString += "Text Text Text Text Text Text Text Text Text Text ";
longString += "Text Text Text Text Text Text Text Text Text .";
g.DrawString(longString, trFont, Brushes.Black, rect);
}
private void InitializeComponent()
{
this.Size = new System.Drawing.Size(300,300);
this.Text = "Form1";
}
static void Main()
{
Application.Run(new Form1());
}
}
Related examples in the same category