GDI+ 绘制有边框的字体
绘制有边框的字体,如图
思路,通过stringMessure来获取字体的长度。
如下:
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
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(0, 0), sf);
g.DrawRectangle(Pens.Red, rf.Left, rf.Top, rf.Width, f.Height);
g.DrawString(str, f, Brushes.Blue, rf,StringFormat.GenericTypographic);
}
{
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(0, 0), sf);
g.DrawRectangle(Pens.Red, rf.Left, rf.Top, rf.Width, f.Height);
g.DrawString(str, f, Brushes.Blue, rf,StringFormat.GenericTypographic);
}