|
发表于 2020-4-19 07:15:01
|
显示全部楼层
private void button1_Click(object sender, EventArgs e)
{
Graphics g = this.CreateGraphics();
SizeF MyFontSize = SizeF.Empty;
Rectangle MyRect = new Rectangle(0, 0, 200, 100);
Font MyFont = new Font("Arial", 100);
string str = "这里要写qweqwewqewqeqwe什么东西";
MyFontSize = g.MeasureString("String to draw ...", MyFont);
while (MyFontSize.Width > MyRect.Width ||
MyFontSize.Height > MyRect.Height)
{
MyFont = new Font("Arial", (MyFont.Size - .01F));
MyFontSize = g.MeasureString(str, MyFont);
}
g.DrawRectangle(Pens.Black,0,0,MyFontSize.Width,MyFontSize.Height);
g.DrawString(str, MyFont, Brushes.Black, new PointF(0, 0));
}
完整充满一个矩形。 |
|