RichTextBox and UserPaint

I am trying to draw a RichTextBox, but the only way to do this is to call OnPaint/OnPaintBackground .

The problem is that OnPaint or OnPaintBackground are not called if the "UserPaint" flag is not enabled, but when this flag is on, the text itself will not be painted!

how can i solve this?

+4
source share
1 answer

This is the code I use to ensure that OnPaint is called after the RichTextBox has processed the picture first:

 class MyRichTextBox: RichTextBox { private const int WM_PAINT = 15; protected override void WndProc(ref System.Windows.Forms.Message m) { base.WndProc (ref m); if (m.Msg == WM_PAINT && !inhibitPaint) { // raise the paint event using (Graphics graphic = base.CreateGraphics()) OnPaint(new PaintEventArgs(graphic, base.ClientRectangle)); } } private bool inhibitPaint = false; public bool InhibitPaint { set { inhibitPaint = value; } } } 
+8
source

Source: https://habr.com/ru/post/1340308/


All Articles