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

  1. //----------------------------------------------
  2. // TallInTheCenter.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 TallInTheCenter: FontMenuForm
  10. {
  11.      public new static void Main()
  12.      {
  13.           Application.Run(new TallInTheCenter());
  14.      }
  15.      public TallInTheCenter()
  16.      {
  17.           Text = "Tall in the Center";
  18.           Width *= 2;
  19.           strText = Text;
  20.           font = new Font("Times New Roman", 48);
  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.                // Shift the origin to the center of the path.
  33.  
  34.           RectangleF rectf = path.GetBounds();
  35.  
  36.           path.Transform(new Matrix(1, 0, 0, 1, 
  37.                                     -(rectf.Left + rectf.Right) / 2,
  38.                                     -(rectf.Top + rectf.Bottom) / 2));
  39.           rectf = path.GetBounds();
  40.  
  41.                // Modify the path.
  42.  
  43.           PointF[] aptf = path.PathPoints;
  44.  
  45.           for (int i = 0; i < aptf.Length; i++)
  46.                aptf[i].Y *= 2 * (rectf.Width - Math.Abs(aptf[i].X)) / 
  47.                                                                  rectf.Width; 
  48.           path = new GraphicsPath(aptf, path.PathTypes);
  49.  
  50.                // Fill the path.
  51.  
  52.           grfx.TranslateTransform(cx / 2, cy / 2);
  53.           grfx.FillPath(new SolidBrush(clr), path);
  54.      }
  55. }