我尝试按照以下代码在运行时更改字体大小,但我总是得到StackOverflowException
.
protected override void OnResize(EventArgs e)
{
this.bitmapDoubleBuffer = new Bitmap(base.Width, base.Height);
this.backGraphics = Graphics.FromImage(this.bitmapDoubleBuffer);
}
public void ReDrawRuntime()
{
SizeF sizeF = this.backGraphics.MeasureString(this.Text, this.Font);
if (sizeF.Width > this.Size.Width)
{
this.Font = new Font(this.Font.Name, 20, this.Font.Style);
sizeF = this.backGraphics.MeasureString(this.Text, this.Font);
}
this.backGraphics.DrawString(this.Text,
this.Font,
this.solidBrushForeColor,
(float)((int)width),
(float)((int)height));
this.graphicsDoubleBuffer.DrawImage(this.bitmapDoubleBuffer, 0, 0);
}