Hi All,
I need to have a text box that displays text in different colors. I
tired overriding WndProc but I still couldn't. Below is the code
snippet I'm using.
Would appreciate if someone could help me out with this (wolud
appreciate if the solution is done using WndProc)
const int WM_PAINT = 0xF;
[DllImport("user32.dll")]
public static extern IntPtr GetWindowDC(IntPtr hWnd);
[DllImport("user32.dll")]
public static extern int ReleaseDC(IntPtr hWnd, IntPtr hDC);
protected override void WndProc(ref
System.Windows.Forms.Message m)
{
base.WndProc(ref m);
switch (m.Msg)
{
case WM_PAINT:
IntPtr hDC = GetWindowDC(m.HWnd);
Graphics graph = Graphics.FromHdc(hDC);
graph.DrawString(this.Text, this.Font, new
SolidBrush(Color.Red), 1.6F, 2.5F);
graph.Dispose();
ReleaseDC(m.HWnd, hDC);
m.Result = IntPtr.Zero;
break;
}
}
Thanks!
Shehan
p.s. I'm using .net2.0 (if its of any help)
Alexander Ubillus - 29 Jun 2006 18:50 GMT
Hi Shehan ,
Why don't you use a RichTextBox ? it behaves exactly as the TextBox but it
lets you apply several colors and font styles to text.
Overriding a core common control functionality will cost you much time. You
would also have to override the Key pressing because it also makes the
textbox draw its text.
> Hi All,
>
[quoted text clipped - 36 lines]
>
> p.s. I'm using .net2.0 (if its of any help)