I'd like to offer a "funny" alternative by using a dummy
TextBox
.
public static Bitmap GetPlainTextBitmap(string strText, Font font, Color colorBack, Color colorText, Size sizeTargetBitmap)
{
TextBox txDummy = new TextBox();
txDummy.BorderStyle = BorderStyle.None;
txDummy.Multiline = true;
txDummy.Size = sizeTargetBitmap;
txDummy.Text = strText;
txDummy.Font = font;
txDummy.BackColor = colorBack;
txDummy.ForeColor = colorText;
Bitmap bmp = new Bitmap(txDummy.Width, txDummy.Height);
txDummy.DrawToBitmap(bmp, txDummy.ClientRectangle);
return bmp;
}