public partial class ExTextbox : TextBox
{
private const int WM_PAINT = 0xF;
private const int WM_NC_PAINT = 0x85;
private IntPtr hDC;
private Graphics gdc;
private Rectangle rectBorder;
private Color borderColor = Color.Black;
[DllImport("user32")]
private static extern IntPtr GetWindowDC(IntPtr hWnd);
[DllImport("user32")]
private static extern IntPtr GetDC(IntPtr hWnd);
[DllImport("user32")]
private static extern int ReleaseDC(IntPtr hWnd, IntPtr hDC);
[Category("Appearance")]
public Color BorderColor
{
get { return this.borderColor; }
set { this.borderColor = value; }
}
public ExTextbox()
{
this.hDC = GetDC(Handle);
this.gdc = Graphics.FromHdc(hDC);
this.rectBorder = new Rectangle(0, 0, this.Width, this.Height);
this.BorderStyle = BorderStyle.FixedSingle;
this.SetStyle(ControlStyles.OptimizedDoubleBuffer, true);
}
protected override void WndProc(ref Message m)
{
switch (m.Msg)
{
case WM_NC_PAINT:
break;
case WM_PAINT:
base.WndProc(ref m);
//ControlPaint.DrawBorder(gdc, this.rectBorder, this.borderColor, ButtonBorderStyle.Solid);
break;
default:
base.WndProc(ref m);
break;
}
}
protected override void OnResize(EventArgs e)
{
this.hDC = GetDC(Handle);
this.gdc = Graphics.FromHdc(hDC);
this.rectBorder = new Rectangle(0, 0, this.Width, this.Height);
Invalidate();
base.OnResize(e);
}
}
|