StringFormat.GenericTypographic : StringFormat « System.Drawing « C# / C Sharp by API






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.new StringFormat(StringFormatFlags.DirectionVertical)
2.StringFormat.Alignment
3.StringFormat.HotkeyPrefix
4.StringFormat.LineAlignment
5.StringFormat.SetTabStops