// clear the background
   Graphics g = this.CreateGraphics();
   g.Clear(Color.AliceBlue);
 
   // create a pen
   Pen pen = new Pen(Color.Red, 1f);
 
   // the string to be drawn
   string s = "S";
 
   // the first font
   Font f1 = new Font("Arial", 10f);
   float strWidth1 = g.MeasureString(s, f1, 500, System.Drawing.StringFormat.GenericTypographic).Width;
   float fontHeight1 = f1.GetHeight(g);     
   float fontAscentHeight1 = (fontHeight1/f1.FontFamily.GetLineSpacing(f1.Style))*f1.FontFamily.GetCellAscent(f1.Style);
 
   // the second font
   Font f2 = new Font("Arial", 48);
   float fontHeight2 = f2.GetHeight(g);     
   float fontAscentHeight2 = (fontHeight2/f2.FontFamily.GetLineSpacing(f2.Style))*f2.FontFamily.GetCellAscent(f2.Style);

   // draw the base line     
   Point ptStart = new Point(0, this.ClientSize.Height/2);
   Point ptEnd = new Point(this.ClientSize.Width, this.ClientSize.Height/2);
   g.DrawLine(Pens.Black, ptStart, ptEnd);

   // draw string with first font
   g.DrawString(s, f1, Brushes.Red, new PointF(0, ptStart.Y - fontAscentHeight1), System.Drawing.StringFormat.GenericTypographic);
 
   // draw string with second font
   g.DrawString(s, f2, Brushes.Red, new PointF(strWidth1, ptStart.Y - fontAscentHeight2), System.Drawing.StringFormat.GenericTypographic);

posted on 2004-05-26 11:13  hi-justin  阅读(1331)  评论(0编辑  收藏  举报