GDI+ 绘制多行文本,自动换行。
1,主要利用MessageString()这个函数来实现自动换行。截图如下:
代码如下:
View Code
//绘制有边框的字体,并自动换行
private void Form1_Paint(object sender, PaintEventArgs e)
{
Graphics g = e.Graphics;
Font f = new Font("Aris", 15, FontStyle.Italic | FontStyle.Strikeout);
string s = "this is my name ,and what about you ,ok no problems,every is ok,something is goods,program.cs ,I want to make susccfjdkjk,grapeBunch/bmp";
SizeF sf = g.MeasureString(s, f, 100);
RectangleF rf = new RectangleF(20, 20, sf.Width, sf.Height);
g.DrawRectangle(Pens.Red,rf.Left,rf.Top,rf.Width,rf.Height);
g.DrawString(s,f,Brushes.Black,rf);
}
private void Form1_Paint(object sender, PaintEventArgs e)
{
Graphics g = e.Graphics;
Font f = new Font("Aris", 15, FontStyle.Italic | FontStyle.Strikeout);
string s = "this is my name ,and what about you ,ok no problems,every is ok,something is goods,program.cs ,I want to make susccfjdkjk,grapeBunch/bmp";
SizeF sf = g.MeasureString(s, f, 100);
RectangleF rf = new RectangleF(20, 20, sf.Width, sf.Height);
g.DrawRectangle(Pens.Red,rf.Left,rf.Top,rf.Width,rf.Height);
g.DrawString(s,f,Brushes.Black,rf);
}