protected override void OnPaint(PaintEventArgs pe) { IntPtr hDC = pe.Graphics.GetHdc(); try { myRichTextBlock.Draw(hDC, pe.ClipRectangle); } finally { pe.Graphics.ReleaseHdc(hDC); } // Calling the base class OnPaint base.OnPaint(pe); }