I've been experimenting with enabling anti-aliasing of text in various controls in a Windows Forms Application.
I did a bit of research and it seems like the solution is to create a custom control and to override OnPaint()
to modify the TextRenderingHint
. I have used this approach successfully on Label
and Button
controls, but it appears not to work for TextBox
or RichTextBox
controls.
Here is the code I am using to enable anti-aliasing in a custom Label
control:
public partial class CustomLabel : Label
{
private System.Drawing.Text.TextRenderingHint _hint = System.Drawing.Text.TextRenderingHint.AntiAliasGridFit;
public System.Drawing.Text.TextRenderingHint TextRenderingHint
{
get { return this._hint; }
set { this._hint = value; }
}
protected override void OnPaint(PaintEventArgs pe)
{
pe.Graphics.TextRenderingHint = TextRenderingHint;
base.OnPaint(pe);
}
}
Using the same approach for a TextBox
or a RichTextBox
does not appear to work.
The application I'm creating deals primarily with text input and I would really like to use anti-aliasing for all of the displayed text, especially text being typed into a TextBox or RichTextBox or a custom control.