use a 12pt font, and assume the text string must fit into a width of 150 pixels : Text Justify : Graphics C# Source Code


Custom Search

C# Source Code » Graphics » Text Justify »

 

use a 12pt font, and assume the text string must fit into a width of 150 pixels








    
 

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);
    SizeF sf = g.MeasureString(s, f, 150);
    RectangleF rf = new RectangleF(20, 20, sf.Width, sf.Height);

    g.DrawRectangle(Pens.Black, rf.Left, rf.Top, rf.Width, rf.Height);
    g.DrawString(s, f, Brushes.Black, rf); 

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

 
    
   
  
   







HTML code for linking to this page:

Follow Navioo On Twitter

C# Source Code

 Navioo Graphics
» Text Justify