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






StringFormat.Alignment

  
using System;
using System.Drawing;
using System.Windows.Forms;
   
class HelloCenteredRectangle: Form
{
     public static void Main() 
     {
          Application.Run(new HelloCenteredRectangle()); 
     }
     public HelloCenteredRectangle()
     {
          BackColor = SystemColors.Window;
          ForeColor = SystemColors.WindowText;
          ResizeRedraw = true;
     }
     protected override void OnPaint(PaintEventArgs pea)
     {
          Graphics     grfx   = pea.Graphics;
          StringFormat strfmt = new StringFormat();
   
          strfmt.Alignment     = StringAlignment.Center;
          strfmt.LineAlignment = StringAlignment.Center;
   
          grfx.DrawString("Hello, world!", Font, new SolidBrush(ForeColor),
                          ClientRectangle, strfmt);
     }
}

   
    
  








Related examples in the same category

1.new StringFormat(StringFormatFlags.DirectionVertical)
2.StringFormat.GenericTypographic
3.StringFormat.HotkeyPrefix
4.StringFormat.LineAlignment
5.StringFormat.SetTabStops