Windows Forms Programming In C# 读书笔记 - 第五章 Drawing Text
1。空心字(只有外边缘的字,需要比较大的字号才能效果好 )
主要用了 GraphicsPath 类
主要用了 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);
}
}
{
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);
}
}