msevnt.cbSize = Marshal.SizeOf(typeof(TRACKMOUSEEVENT));
msevnt.dwFlags = TME_HOVER;
msevnt.hwndTrack = (long)this.Handle;
msevnt.dwHoverTime = 300;
if (m.WParam.ToInt32() == VK_LBUTTON)
{
Point newCursor = GetPointFromLPARAM(m.LParam.ToInt32());
this.Location = new Point(this.Location.X + newCursor.X - this._mouseDownPos.X,
this.Location.Y + newCursor.Y - this._mouseDownPos.Y);
}
}
break;
default:
break;
}
}
///
/// 获得低16位值
///
///
///
public static int GET_X_LPARAM(int lParam) { return (lParam & 0xffff); }
///
/// 获得高16位值
///
///
///
public static int GET_Y_LPARAM(int lParam) { return (lParam >> 16); }
///
/// 解析出鼠标的新坐标(相对于窗体的坐标)
///
///
///
public static Point GetPointFromLPARAM(int lParam)
{ return new Point(GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam)); }
private Point _mouseDownPos = new Point();
private void button1_Click(object sender, EventArgs e)
{
this.Close();
}
}
}