爱猫的狗

拥抱变化

导航

Windows Forms Programming In C# 读书笔记 - 第五章 Drawing Text

1。空心字(只有外边缘的字,需要比较大的字号才能效果好 ) 

    主要用了 GraphicsPath 类

GraphicsPath GetStringPath( string s, float dpi, RectangleF rect, Font font, StringFormat format) 
{

    GraphicsPath path 
= new GraphicsPath();
    
// Convert font size into appropriate coordinates
    float emSize = dpi * font.SizeInPoints / 72;
    path.AddString( s, font.FontFamily, (
int)font.Style, emSize, rect, format);
    
return path;
}



private void panel1_Paint(object sender, System.Windows.Forms.PaintEventArgs e)
{
    Graphics g 
= e.Graphics;
    
string s = "Outline";
    RectangleF rect 
= this.ClientRectangle;
    Font font 
= new Font("Arial"32, GraphicsUnit.Point);
    StringFormat format 
= StringFormat.GenericTypographic;
    
float dpi = g.DpiY;
    
using( GraphicsPath path = GetStringPath(s, dpi, rect, font, format) ) 
    
{
           g.DrawPath(Pens.Black, path);
    }

}

posted on 2005-03-04 11:15  anf  阅读(648)  评论(1编辑  收藏  举报