home *** CD-ROM | disk | FTP | other *** search
/ Programming in Microsoft Windows with C# / Programacion en Microsoft Windows con C#.iso / Original Code / Pages and Transforms / PenWidths / PenWidths.cs next >
Encoding:
Text File  |  2001-01-15  |  1.1 KB  |  39 lines

  1. //----------------------------------------
  2. // PenWidths.cs ⌐ 2001 by Charles Petzold
  3. //----------------------------------------
  4. using System;
  5. using System.Drawing;
  6. using System.Windows.Forms;
  7.  
  8. class PenWidths: PrintableForm
  9. {
  10.      public new static void Main()
  11.      {
  12.           Application.Run(new PenWidths());
  13.      }
  14.      public PenWidths()
  15.      {
  16.           Text = "Pen Widths";
  17.      }
  18.      protected override void DoPage(Graphics grfx, Color clr, int cx, int cy)
  19.      {
  20.           Brush brush = new SolidBrush(clr);
  21.           float y     = 0;
  22.  
  23.           grfx.PageUnit  = GraphicsUnit.Point;
  24.           grfx.PageScale = 1;
  25.  
  26.           for (float f = 0; f < 3.2; f += 0.2f)
  27.           {
  28.                Pen    pen   = new Pen(clr, f);
  29.                string str   = String.Format("{0:F1}-point-wide pen: ", f);
  30.                SizeF  sizef = grfx.MeasureString(str, Font);
  31.  
  32.                grfx.DrawString(str, Font, brush, 0, y);
  33.                grfx.DrawLine(pen, sizef.Width,       y + sizef.Height / 2,
  34.                                   sizef.Width + 144, y + sizef.Height / 2);
  35.                y += sizef.Height;
  36.           }
  37.      }
  38. }
  39.