试试这个:
public partial class Form1 : Form {
private const int WM_NCLBUTTONDOWN = 0xA1;
private const int HT_CAPTION = 0x2;
[DllImportAttribute("user32.dll")]
private static extern int SendMessage(IntPtr hWnd, int Msg, int wParam, int lParam);
[DllImportAttribute("user32.dll")]
private static extern bool ReleaseCapture();
public Form1() {
InitializeComponent();
Form f = new Form();
f.MouseDown += ChildForm_MouseDown;
f.MdiParent = this;
f.Show();
}
void ChildForm_MouseDown(object sender, MouseEventArgs e) {
if (e.Button == MouseButtons.Left) {
ReleaseCapture();
SendMessage(this.Handle, WM_NCLBUTTONDOWN, HT_CAPTION, 0);
}
}
}
MDI父窗体是听孩子鼠标按下事件,当用户单击子窗体上,它会像用户点击的标题栏主要形式。
伟大的作品,谢谢 - 只需要确保使用'System.Runtime.InteropServices;'是包括在内。 –