using System;
using System.ComponentModel;
using System.Runtime.InteropServices;
using System.Windows.Forms;
using System.Drawing;
namespace WindowsApplication6
{
class UserControl2 : System.Windows.Forms.TextBox
{
[DllImport("user32.dll")]
static extern IntPtr GetWindowDC(IntPtr hWnd);
[DllImport("user32.dll")]
static extern int ReleaseDC(IntPtr hWnd, IntPtr hDC);
const int WM_NCCALCSIZE = 0x0083;
const int WM_NCHITTEST = 0x0084;
const int WM_NCPAINT = 0x0085;
struct RECT
{
public Int32 left;
public Int32 top;
public Int32 right;
public Int32 bottom;
};
protected override void OnPaint(PaintEventArgs e)
{
base.OnPaint (e);
IntPtr hDC = GetWindowDC(Handle);
if (hDC.ToInt32() == 0)
{
return;
}
Graphics g = Graphics.FromHdc(hDC);
Brush b = Brushes.Red;
Pen p = new Pen(b,5);
Rectangle r = new
Rectangle(0,0,this.Size.Width,this.Size.Height);
g.DrawRectangle(p,r);
ReleaseDC(Handle,hDC);
}
protected override void WndProc(ref Message m)
{
switch(m.Msg)
{
case WM_NCHITTEST:
{
base.WndProc(ref m);
IntPtr hDC = GetWindowDC(m.HWnd);
if (hDC.ToInt32() == 0)
{
break;
}
Brush b;
b = Brushes.Red;
Graphics g = Graphics.FromHdc(hDC);
Pen p = new Pen(b,5);
Rectangle r = new
Rectangle(0,0,this.Size.Width,this.Size.Height);
g.DrawRectangle(p,r);
m.Result = IntPtr.Zero;
ReleaseDC(m.HWnd,hDC);
return;
}
}
base.WndProc(ref m);
}
}
}