I have subclassed a control in C# WinForms, and am custom drawing text in my OnPaint()
handler.
The font is set to Courier New using the following code in my form:
FontFamily family = new FontFamily("Courier New");
this.myControl.Font = new Font(family, 10);
In the control itself, the string is stored in realText
, and I use the following code to draw it to the screen:
protected override void OnPaint(PaintEventArgs e)
{
base.OnPaint(e);
e.Graphics.DrawString(realText, Font, new SolidBrush(ForeColor), ClientRectangle);
}
The result for some random example text looks as follows: http://img219.imageshack.us/img219/1778/courier.png
If you zoom in, you can see for example, that the space between the first 'as' is different than the space between the second 'as' (1 pixels versus 2 pixels). Does anybody have any idea what might be causing this, or how I can prevent it from happening? There is a lot more similar weirdness in spacing as I draw with different fonts, but I assume they're all results of the same problem.
Thanks in advance for any ideas you may have.