public partial class ResizableRichTextBox : RichTextBox
{
public ResizableRichTextBox()
{
InitializeComponent();
}
public ResizableRichTextBox(IContainer container)
{
container.Add(this);
InitializeComponent();
}
[DllImport("user32.dll")]
private static extern int GetSystemMetrics(int nIndex);
private const int WM_NCHITTEST = 0x84;
private const int HTBOTTOM = 15;
private const int HTBOTTOMLEFT = 16;
private const int HTBOTTOMRIGHT = 17;
private const int HTTOP = 12;
private const int HTTOPLEFT = 13;
private const int HTTOPRIGHT = 14;
private const int HTLEFT = 10;
private const int HTRIGHT = 11;
private const int WM_EXPAND = WM_USER + 67;
private const int WM_USER = 0x0400;
protected override void WndProc(ref Message m)
{
base.WndProc(ref m);
switch (m.Msg)
{
case WM_NCHITTEST:
base.WndProc(ref m);
Point vPoint = new Point((int)m.LParam & 0xFFFF,
(int)m.LParam >> 16 & 0xFFFF);
vPoint = this.PointToClient(vPoint);
if (vPoint.X <= 5)
{
if (vPoint.Y <= 5)
m.Result = (IntPtr)HTTOPLEFT;
else if (vPoint.Y >= this.Height - 5)
m.Result = (IntPtr)HTBOTTOMLEFT;
else
m.Result = (IntPtr)HTLEFT;
}
else if (vPoint.X >= this.Width - 5)
{
if (vPoint.Y <= 5)
m.Result = (IntPtr)HTTOPRIGHT;
else if (vPoint.Y >= this.Height - 5)
m.Result = (IntPtr)HTBOTTOMRIGHT;
else
m.Result = (IntPtr)HTRIGHT;
}
else if (vPoint.Y <= 5)
m.Result = (IntPtr)HTTOP;
else if (vPoint.Y >= this.Height - 5)
m.Result = (IntPtr)HTBOTTOM;
break;
}
}
}