GDI+ 绘制有边框的字体

绘制有边框的字体,如图

 

思路,通过stringMessure来获取字体的长度。

如下:

View Code
        private void Form1_Paint(object sender, PaintEventArgs e)
        {
            Graphics g 
= e.Graphics;
            FontFamily ff 
= new FontFamily(GenericFontFamilies.Serif);
            Font f 
= new Font(ff, 12, FontStyle.Italic);
            
string str = "Height" + f.Height;
            
//不添加而外的高度
            SizeF sf = g.MeasureString(str, f, int.MaxValue,StringFormat.GenericTypographic);
            RectangleF rf 
= new RectangleF(new PointF(00), sf);
            g.DrawRectangle(Pens.Red, rf.Left, rf.Top, rf.Width, f.Height);
            g.DrawString(str, f, Brushes.Blue, rf,StringFormat.GenericTypographic);

        }

posted on 2011-07-30 00:59  wtq  阅读(1366)  评论(0编辑  收藏  举报