I'm trying to draw borders around words and paragraphs in RichTextBox but when I turn on UserPaint it doesn't draw text anymore while my custom painting seems to work. May be I just forgot to turn on something else? Here is what I have
public partial class RichTextBoxEx : RichTextBox
{
public RichTextBoxEx()
{
InitializeComponent();
SetStyle(ControlStyles.UserPaint, true);
}
protected override void OnPaint(PaintEventArgs e)
{
base.OnPaint(e);
//Do some painting here
}
}
Using info from this question didn't help me
This worked ok for me:
class RichBox : RichTextBox {
private const int WM_PAINT = 15;
protected override void WndProc(ref Message m) {
if (m.Msg == WM_PAINT) {
this.Invalidate();
base.WndProc(ref m);
using (Graphics g = Graphics.FromHwnd(this.Handle)) {
g.DrawLine(Pens.Red, Point.Empty,
new Point(this.ClientSize.Width - 1,
this.ClientSize.Height - 1));
}
} else {
base.WndProc(ref m);
}
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With