Create new Windows Forms project. Add Button to form and double-click it to create
Click event handler. Add following code to Button Click event handler:
Graphics gForm = this.CreateGraphics();
Bitmap bmp = new Bitmap(100,
100, gForm);
Graphics g = Graphics.FromImage(bmp);
g.FillRectangle(SystemBrushes.ControlLight,
0, 0, 100, 100);
Font font = this.Font;
TextRenderer.DrawText(g,
“Does not look good…”, font, new Point(10, 20),
SystemColors.ControlText,
TextFormatFlags.Default);
g.Dispose();
gForm.DrawImageUnscaled(bmp,
0,0);
bmp.Dispose();
gForm.Dispose();
Text rendered will not look good… Graphics.DrawString works just fine it is
problem with the TextRenderer.DrawText in .NET Framework 2.0.
Note that this happens only if ClearType is selected in Windows Display Properties
for smoothing font edges.
Conclusion, do not use TextRenderer.DrawText to draw text on bitmaps you create, that
is if you want it to look good :-)… Use Graphics.DrawString.
Hopefully this saves someone time…
Denis Basaric, DevComponents LLC.