D
digitalshehan
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)
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)