Use System.Windows.Forms.TextRenderer .
Just override the methods from System.Windows.Forms.Control :
protected override void OnPaint(PaintEventArgs e) { TextRenderer.DrawText(e.Graphics, Text, Font, new Rectangle(0, 0, Width, Height), ForeColor); } public override Size GetPreferredSize(Size proposedSize) { return TextRenderer.MeasureText(Text, Font); }
Of course, you will need to handle a couple more events, such as OnFontChanged or OnSizeChanged , if you need to perform individual behavior.
If what you are looking for is for specific text (selected text) in these controls, you can take a look at this article . The source code for the spelling check library (SharpSpell) is also associated with this article.
source share