转载博客园,代码未经本人测试。
[C#] 纯文本查看 复制代码 /// <summary>设置可以鼠标左键让窗体移动的控件
/// </summary>
/// <param name="form">待移动的窗体,通常是设置了FormBorderStyle = FormBorderStyle.None的窗体</param>
/// <param name="control">能控制窗体左键移动的控件</param>
public static void SetMoveFormControl(Form form, Control control)
{
control.MouseDown += (s, e) =>
{
ReleaseCapture();
SendMessageA((int)form.Handle, 0xa1, 2, 0);
};
}
[DllImport("user32.dll")]
private static extern int ReleaseCapture();
[DllImport("user32.dll")]
private static extern int SendMessageA(int hwnd, int wMsg, int wParam, int lParam);
|