一、本文主要讲述两种情况,即运行时窗体内控件的移动和窗体随控件一起移动:
大致做法如下:
引入两个API函数:
[System.Runtime.InteropServices.DllImport("user32.dll", EntryPoint = "SendMessage")]
public static extern int SendMessage(int hWnd, int wMsg, int wParam, int lParam);
[System.Runtime.InteropServices.DllImport("user32.dll", EntryPoint = "ReleaseCapture")]
public static extern int ReleaseCapture();
public const int WM_SysCommand = 0x0112;
public const int SC_MOVE = 0xF012;
然后在想要移动的控件的MouseDown事件内添加如下代码,这里以Panel的MouseDown为例:
void panel1_MouseDown(object sender, MouseEventArgs e)
{
ReleaseCapture();
SendMessage(this.Handle.ToInt32(),WM_SysCommand,