110,536
社区成员
发帖
与我相关
我的任务
分享
public class MyPanel : Panel
{
private const int cGrip = 16; // Grip size
private const int cCaption = 25; // Caption bar height;
protected override void WndProc(ref Message m)
{
if (m.Msg == 0x84)
{ // Trap WM_NCHITTEST
Point pos = new Point(m.LParam.ToInt32() & 0xffff, m.LParam.ToInt32() >> 16);
pos = this.PointToClient(pos);
Console.WriteLine(pos);
if (pos.Y < cCaption)
{
m.Result = (IntPtr)2; // HTCAPTION
return;
}
if (pos.X >= this.ClientSize.Width - cGrip && pos.Y >= this.ClientSize.Height - cGrip)
{
m.Result = (IntPtr)17; // HTBOTTOMRIGHT
return;
}
}
base.WndProc(ref m);
}
#region "拖动窗体"
private bool moveFlag = false;
private int x = 0;
private int y = 0;
protected override void OnMouseMove(System.Windows.Forms.MouseEventArgs e)
{
if (moveFlag && (e.Button == MouseButtons.Left))
this.SetBounds(Left + e.X - x, Top + e.Y - y, this.Width, this.Height);
base.OnMouseMove(e);
}
protected override void OnMouseDown(System.Windows.Forms.MouseEventArgs e)
{
if (!moveFlag && e.Clicks >= 1)
moveFlag = true;
x = e.X;
y = e.Y;
base.OnMouseDown(e);
}
protected override void OnMouseUp(System.Windows.Forms.MouseEventArgs e)
{
if (moveFlag)
moveFlag = false;
base.OnMouseUp(e);
}
#endregion "拖动窗体"
}