is there a way I can resize a borderless form with controls that are on the border with one code?
The Problem is I can't resize when I put a close, maximize and minimize button in the top right corner.
Close, Maximize & Minimize Buttons Image
I know, it's possible with this code to resize all sub controls. But the problem is I can't use the full space of the Buttons. If I m too near to the border with my cursor it switches to the resizer.
private void Controls_Bar_Top_Load(object sender, EventArgs e)
{
subClassChildren(this.Controls);
}
const int edge = -32;
class MouseFilter : NativeWindow
{
private Form form;
public MouseFilter(Form form, Control child)
{
this.form = form;
this.AssignHandle(child.Handle);
}
protected override void WndProc(ref Message m)
{
const int wmNcHitTest = 0x84;
const int htTransparent = -1;
if (m.Msg == wmNcHitTest)
{
var pos = new Point(m.LParam.ToInt32());
if (pos.X < this.form.Left + edge ||
pos.Y < this.form.Top + edge ||
pos.X > this.form.Right - edge ||
pos.Y > this.form.Bottom - edge)
{
m.Result = new IntPtr(htTransparent);
return;
}
}
base.WndProc(ref m);
}
}
private void subClassChildren(Control.ControlCollection ctls)
{
foreach (Control ctl in ctls)
{
var rc = this.RectangleToClient(this.RectangleToScreen(ctl.DisplayRectangle));
if (rc.Left < edge || rc.Right > this.ClientSize.Width - edge ||
rc.Top < edge || rc.Bottom > this.ClientSize.Height - edge)
{
new MouseFilter(this.ParentForm, ctl);
}
subClassChildren(ctl.Controls);
}
}
I just want a code where the resize pointer just shows up when I hit the shadow of the control. Right now it shows already up when I am like 5px away from the shadow.
The Code I use for my form to resize is this:
protected override void WndProc(ref Message m)
{
const int RESIZE_HANDLE_SIZE = 10;
switch (m.Msg)
{
case 0x0084/*NCHITTEST*/ :
base.WndProc(ref m);
if ((int)m.Result == 0x01/*HTCLIENT*/)
{
Point screenPoint = new Point(m.LParam.ToInt32());
Point clientPoint = this.PointToClient(screenPoint);
if (clientPoint.Y <= RESIZE_HANDLE_SIZE)
{
if (clientPoint.X <= RESIZE_HANDLE_SIZE)
m.Result = (IntPtr)13/*HTTOPLEFT*/ ;
else if (clientPoint.X < (Size.Width - RESIZE_HANDLE_SIZE))
m.Result = (IntPtr)12/*HTTOP*/ ;
else
m.Result = (IntPtr)14/*HTTOPRIGHT*/ ;
}
else if (clientPoint.Y <= (Size.Height - RESIZE_HANDLE_SIZE))
{
if (clientPoint.X <= RESIZE_HANDLE_SIZE)
m.Result = (IntPtr)10/*HTLEFT*/ ;
else if (clientPoint.X < (Size.Width - RESIZE_HANDLE_SIZE))
m.Result = (IntPtr)1/*HTCAPTION*/ ;
else
m.Result = (IntPtr)11/*HTRIGHT*/ ;
}
else
{
if (clientPoint.X <= RESIZE_HANDLE_SIZE)
m.Result = (IntPtr)16/*HTBOTTOMLEFT*/ ;
else if (clientPoint.X < (Size.Width - RESIZE_HANDLE_SIZE))
m.Result = (IntPtr)15/*HTBOTTOM*/ ;
else
m.Result = (IntPtr)17/*HTBOTTOMRIGHT*/ ;
}
}
return;
case WM_NCPAINT:
if (m_aeroEnabled)
{
var v = 2;
DwmSetWindowAttribute(this.Handle, 2, ref v, 4);
MARGINS margins = new MARGINS()
{
bottomHeight = 1,
leftWidth = 0,
rightWidth = 0,
topHeight = 0
}; DwmExtendFrameIntoClientArea(this.Handle, ref margins);
}
break;
default: break;
}
base.WndProc(ref m);