WinFormsFAQ & RTF-Control

Malfunction

Well-known member
Joined
Dec 8, 2003
Messages
203
Location
Berlin, Germany
Maybe its just me ... but ...
Id like to see this added to the RichTextBox section of the WinForms FAQ:

1. How to paint something on the RTB when the paint-event is never called.
(Code example below)
2. Why are some operations (e.g. AppendText) awfully slow.
(Read this for an explanation: Nice Link )

I found many people asking these questions but only few answers.


The Code Im using to draw a border around an inherited RichTextBox:

Code:
using System.Runtime.InteropServices;

[DllImport("user32")]
		private static extern IntPtr GetDC(
			IntPtr hWnd);

		[DllImport("user32")]
		private static extern int ReleaseDC(
			IntPtr hWnd, 
			IntPtr hdc);
protected override void WndProc(ref Message m)
		{
			if (m.Msg == 0x85 || m.Msg == 0xF)
			{
				base.WndProc (ref m);
				this.paintBorder();
			}
			else
			{
				base.WndProc (ref m);
			}
		}
		private void paintBorder()
		{
			Rectangle rcItem;
			IntPtr hDC = IntPtr.Zero;

			rcItem = new Rectangle(this.Left - 1, this.Top - 1, this.Width + 1, this.Height + 1);

			hDC = GetDC(this.Parent.Handle);
			Graphics gfx = Graphics.FromHdc(hDC);

			Pen pen = new Pen(Color.Black,1);
			gfx.DrawRectangle(pen, rcItem);

			pen.Dispose();
			gfx.Dispose();
			ReleaseDC(this.Handle, hDC);
		}
 
Last edited by a moderator:
Back
Top