試試這個:
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;'是包括在內。 –