المساعد الشخصي الرقمي

مشاهدة النسخة كاملة : Border color of Textbox not working



C# Programming
06-26-2009, 01:23 PM
I would like to change the border color of Text Box in C#. I subclassed the TextBox control and override the WndProc function to catch the PAINT Messages to draw the border with my color.

But the border color hasn't changed, still i am getting the default border color of text box that is Black color. The same code works fine with .NET 1.0 but not working in .NET 2.0 and the latest versions.

Can anyone tell what is the difference between .NET 1.0 painting and .NET 2.0 painting for TextBox?


using System;
using System.Collections.Generic;
using System.Text;
using System.Windows.Forms;
using System.Runtime.InteropServices;
using System.Drawing;

class MyTextBox : TextBox {
private const int WM_NCPAINT = 0x85;
private const int WM_ERASEBKGND = 0x14;
private const int WM_PAINT = 0xF;
[DllImport("user32.dll")]
static extern IntPtr GetDCEx(IntPtr hWnd, IntPtr hrgnClip, int flags);
[DllImport("user32.dll")]
static extern int ReleaseDC(IntPtr hWnd, IntPtr hDC);

protected override void WndProc(ref Message message) {
base.WndProc(ref message);
if (message.Msg == WM_PAINT)
{
//get handle to a display device context
IntPtr hdc = GetDCEx(message.HWnd, (IntPtr)1, 1 | 0x0020);

if (hdc != IntPtr.Zero) {
//get Graphics object from the display device context
Graphics graphics = Graphics.FromHdc(hdc);
Rectangle rectangle = new Rectangle(0, 0, Width, Height);
ControlPaint.DrawBorder(graphics, rectangle, Color.White, ButtonBorderStyle.Solid);

message.Result = (IntPtr)1;
ReleaseDC(message.HWnd, hdc);
}
}
}
}



Thanks in advance