C# WInForm 无框窗体移动
调用APIusing System.Runtime.InteropServices;
public static extern bool ReleaseCapture();
public static extern bool SendMessage(IntPtr hwnd, int wMsg, int wParam, int lParam);
public const int WM_SYSCOMMAND = 0x0112;
public const int SC_MOVE = 0xF010;
public const int HTCAPTION = 0x0002;在控件的_MouseDown中加入如下代码:private void Form1_MouseDown(object sender, System.Windows.Forms.MouseEventArgs e)
{
ReleaseCapture();
SendMessage(this.Handle, WM_SYSCOMMAND, SC_MOVE + HTCAPTION, 0);
} Good Old Trick {:3_48:} 不错,呵呵,谢谢楼主分享 学习了,支持楼主的奉献精神。 学习学习! 很不错!!!支持一下楼主 很好...GOOD 一个... 谢谢楼主分享 感谢楼主分享! ibm2000 发表于 2013-12-2 13:31
感谢楼主分享!
如果不想用引用的话 可以这样
private Point offset;
private void BudgetSheetForm_MouseDown(object sender, MouseEventArgs e)
{
if (MouseButtons.Left != e.Button) return;
Point cur = this.PointToScreen(e.Location);
offset = new Point(cur.X - this.Left, cur.Y - this.Top);
}
private void BudgetSheetForm_MouseMove(object sender, MouseEventArgs e)
{
if (MouseButtons.Left != e.Button) return;
Point cur = MousePosition;
this.Location = new Point(cur.X - offset.X, cur.Y - offset.Y);
}
页:
[1]