目的:
1、将窗体设置成无边框,如下面效果图
2、该无边框窗体添加了窗体放大、缩小(可以根据需要只能横向放大缩小 或者 竖向放大缩小)的功能
Point vPoint = new Point((int)m.LParam & 0xFFFF, (int)m.LParam >> 16 & 0xFFFF);
vPoint = PointToClient(vPoint);
if (vPoint.X <= 5)
{
if (vPoint.Y <= 5)
{
m.Result = (IntPtr)GuyingHtTopLeft;
}
else
{
m.Result = vPoint.Y >= ClientSize.Height - 5 ? (IntPtr)GuyingHtBottomLeft : (IntPtr)GuyingHtLeft;
}
}
else if (vPoint.X >= ClientSize.Width - 5)
{
if (vPoint.Y <= 5)
{
m.Result = (IntPtr)GuyingHtTopRight;
}
else
{
m.Result = vPoint.Y >= ClientSize.Height - 5 ? (IntPtr)GuyingHtBottomRight : (IntPtr)GuyingHtRight;
}
}
else if (vPoint.Y <= 5)
{
m.Result = (IntPtr)GuyingHtTop;
}
else if (vPoint.Y >= ClientSize.Height - 5)
{
m.Result = (IntPtr)GuyingHtBottom;
}
3、添加鼠标左键点击
case 0x0201: //鼠标左键按下的消息
if ( /*this.*/Draggable)
{
m.Msg = 0x00A1; //更改消息为非客户区按下鼠标
m.LParam = IntPtr.Zero; //默认值
m.WParam = new IntPtr(2); //鼠标放在标题栏内
}
base.WndProc(ref m);
break;
效果图
源码下载地址: