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

  1. //------------------------------------------
  2. // FourCorners.cs ⌐ 2001 by Charles Petzold
  3. //------------------------------------------
  4. using System;
  5. using System.Drawing;
  6. using System.Windows.Forms;
  7.  
  8. class FourCorners: Form
  9. {
  10.      public static void Main()
  11.      {
  12.           Application.Run(new FourCorners());
  13.      }
  14.      public FourCorners()
  15.      {
  16.           Text = "Four Corners Text Alignment";
  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.           Brush        brush  = new SolidBrush(ForeColor);
  25.           StringFormat strfmt = new StringFormat();
  26.  
  27.           strfmt.Alignment     = StringAlignment.Near;
  28.           strfmt.LineAlignment = StringAlignment.Near;
  29.           grfx.DrawString("Upper left corner", Font, brush, 0, 0, strfmt);
  30.  
  31.           strfmt.Alignment     = StringAlignment.Far;
  32.           strfmt.LineAlignment = StringAlignment.Near;
  33.           grfx.DrawString("Upper right corner", Font, brush, 
  34.                           ClientSize.Width, 0, strfmt);
  35.  
  36.           strfmt.Alignment     = StringAlignment.Near;
  37.           strfmt.LineAlignment = StringAlignment.Far;
  38.           grfx.DrawString("Lower left corner", Font, brush, 
  39.                           0, ClientSize.Height, strfmt);
  40.  
  41.           strfmt.Alignment     = StringAlignment.Far;
  42.           strfmt.LineAlignment = StringAlignment.Far;
  43.           grfx.DrawString("Lower right corner", Font, brush, 
  44.                           ClientSize.Width, ClientSize.Height, strfmt);
  45.      }
  46. }