StringFormat: Alignment, LineAlignment : String Format « 2D Graphics « C# / C Sharp






StringFormat: Alignment, LineAlignment

 
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.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.GenericTypographic