The problem lies in the setting of Dock property to DockStyle.Top. Do not set this property would make the forms stay still when clicking. However, if you stillwant the Dock style, there's a trick to get the same feature, i.e. to set the Anchor property and hard-code the location for the forms, something like this, see the code in bold
Code Block
Form1_Load(object sender, EventArgs e)
{
this.IsMdiContainer = true;
for (int ii = 1; ii < 5; ii++)
{
Form cForm = new Form();
cForm.MdiParent = this;
//cForm.Dock = DockStyle.Top;
cForm.Anchor = AnchorStyles.Left | AnchorStyles.Right | AnchorStyles.Top;
cForm.Size = new Size(this.Width, 40);
cForm.Top = (ii - 1) * cForm.Height;
cForm.Text = "Child " + ii.ToString();
cForm.MouseDown += new MouseEventHandler(cForm_MouseDown);
cForm.Show();
}
}
void cForm_MouseDown(object sender, MouseEventArgs e)
{
MessageBox.Show("Mouse Down");
}
|