home *** CD-ROM | disk | FTP | other *** search
/ Programming in Microsoft Windows with C# / Programacion en Microsoft Windows con C#.iso / Original Code / Font Fun / HollowFontCenteredPath / HollowFontCenteredPath.cs next >
Encoding:
Text File  |  2001-01-15  |  1.5 KB  |  47 lines

  1. //-----------------------------------------------------
  2. // HollowFontCenteredPath.cs ⌐ 2001 by Charles Petzold
  3. //-----------------------------------------------------
  4. using System;
  5. using System.Drawing;
  6. using System.Drawing.Drawing2D;
  7. using System.Windows.Forms;
  8.  
  9. class HollowFontCenteredPath: FontMenuForm
  10. {
  11.      public new static void Main()
  12.      {
  13.           Application.Run(new HollowFontCenteredPath());
  14.      }
  15.      public HollowFontCenteredPath()
  16.      {
  17.           Text = "Hollow Font (Centered Path)";
  18.           Width *= 2; 
  19.           strText = "Hollow";
  20.           font = new Font("Times New Roman", 108);
  21.      }
  22.      protected override void DoPage(Graphics grfx, Color clr, int cx, int cy)
  23.      {
  24.           GraphicsPath path = new GraphicsPath();
  25.           float fFontSize = PointsToPageUnits(grfx, font);
  26.  
  27.                // Add text to the path.
  28.  
  29.           path.AddString(strText, font.FontFamily, (int) font.Style,
  30.                          fFontSize, new PointF(0, 0), new StringFormat());
  31.  
  32.                // Get the path bounds for centering.
  33.  
  34.           RectangleF rectfBounds = path.GetBounds();
  35.           
  36.           grfx.TranslateTransform(
  37.                          (cx - rectfBounds.Width) / 2 - rectfBounds.Left,
  38.                          (cy - rectfBounds.Height) / 2 - rectfBounds.Top);
  39.  
  40.                // Draw the path.
  41.  
  42.           Pen pen = new Pen(clr, fFontSize / 50);
  43.           pen.DashStyle = DashStyle.Dot;
  44.  
  45.           grfx.DrawPath(pen, path);
  46.      }
  47. }