using System; using System.Drawing; using System.Windows.Forms; class MainForm : Form { [STAThread] static void Main () { Application.Run (new MainForm ()); } protected override void OnPaint (PaintEventArgs pevent) { base.OnPaint (pevent); Graphics g = pevent.Graphics; String s = "The quick brown fox jumped over the lazy dogs."; // Regular Rectangle r1 = new Rectangle (0, 0, 140, 14); g.DrawRectangle (Pens.Red, r1); g.DrawString (s, Font, Brushes.Black, r1); g.DrawString ("Regular", Font, Brushes.Black, 150, 2); // Line Limit Rectangle r2 = new Rectangle (0, 40, 140, 14); StringFormat sf = new StringFormat (); sf.Trimming = StringTrimming.EllipsisCharacter; g.DrawRectangle (Pens.Red, r2); g.DrawString (s, Font, Brushes.Black, r2, sf); g.DrawString ("EllipsisCharacter", Font, Brushes.Black, 150, 42); // Line Limit - Not enough room for any lines Rectangle r3 = new Rectangle (0, 80, 140, 14); g.DrawRectangle (Pens.Red, r3); sf.Trimming = StringTrimming.EllipsisWord; g.DrawString (s, Font, Brushes.Black, r3, sf); g.DrawString ("EllipsisWord", Font, Brushes.Black, 150, 82); } }