home *** CD-ROM | disk | FTP | other *** search
/ Programming in Microsoft Windows with C# / Programacion en Microsoft Windows con C#.iso / Original Code / Essential Structures / HelloCenteredRectangle / HelloCenteredRectangle.cs next >
Encoding:
Text File  |  2001-01-15  |  1.0 KB  |  32 lines

  1. //-----------------------------------------------------
  2. // HelloCenteredRectangle.cs ⌐ 2001 by Charles Petzold
  3. //-----------------------------------------------------
  4. using System;
  5. using System.Drawing;
  6. using System.Windows.Forms;
  7.  
  8. class HelloCenteredRectangle: Form
  9. {
  10.      public static void Main() 
  11.      {
  12.           Application.Run(new HelloCenteredRectangle()); 
  13.      }
  14.      public HelloCenteredRectangle()
  15.      {
  16.           Text = "Hello Centered Using Rectangle";
  17.           BackColor = SystemColors.Window;
  18.           ForeColor = SystemColors.WindowText;
  19.           ResizeRedraw = true;
  20.      }
  21.      protected override void OnPaint(PaintEventArgs pea)
  22.      {
  23.           Graphics     grfx   = pea.Graphics;
  24.           StringFormat strfmt = new StringFormat();
  25.  
  26.           strfmt.Alignment     = StringAlignment.Center;
  27.           strfmt.LineAlignment = StringAlignment.Center;
  28.  
  29.           grfx.DrawString("Hello, world!", Font, new SolidBrush(ForeColor), 
  30.                           ClientRectangle, strfmt);
  31.      }
  32. }