StringFormat.GenericTypographic : String Format « 2D Graphics « C# / C Sharp






StringFormat.GenericTypographic

 

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);

      FontFamily ff = new FontFamily("Times New Roman");
      Font f = new Font(ff, 12);
      String s = "Height: " + f.Height;
      SizeF sf = g.MeasureString(s, f, Int32.MaxValue,StringFormat.GenericTypographic);
      RectangleF r = new RectangleF(0, 0, sf.Width, f.Height);

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

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

 








Related examples in the same category

1.Text Columns
2.Text wrap: vertical, horizontal and trimText wrap: vertical, horizontal and trim
3.String format flag: No WrapString format flag: No Wrap
4.String Format Flag: Direction VerticalString Format Flag: Direction Vertical
5.Create a StringFormat object, and set the tab stops, in pixelsCreate a StringFormat object, and set the tab stops, in pixels
6.StringFormat: Alignment, LineAlignment