MdiParent bug...or am I dumb

  • Thread starter Thread starter Robert Conde
  • Start date Start date
R

Robert Conde

Setting the MdiParent of a Form works as expected. However, if an
application has more than one top level mdi container form then unexpected
erroneous behavior is observed when setting the MdiParent of a child form
first to one MdiContainer, and then setting the MdiParent of the same child
form to another container. After setting the MdiParent for a second time,
the child will not activate and when maximized will not merge with main
menu, if available, or the title bar if there is no main menu.

Reproduce with the following code:

using System;
using System.Collections.Generic;
using System.Text;
using System.Windows.Forms;


namespace MDIParentBug
{
class MainForm : Form
{
Form secondMdiForm = new Form();
Form mdiChildForm = new Form();

public MainForm()
{
this.Text = "Main Mdi Form";
secondMdiForm.Text = "Second Mdi Form";

//Set as mdi containers...
secondMdiForm.IsMdiContainer = true;
this.IsMdiContainer = true;

//set the mdi parent of the child
mdiChildForm.MdiParent = this;

//Show second mdi container...
secondMdiForm.Show();

//Hook up activated events..
this.Activated += MDIParent_Activated;
secondMdiForm.Activated += MDIParent_Activated;

//show mdi child...
mdiChildForm.Show();
}

void MDIParent_Activated(object sender, EventArgs e)
{
//set new parent of mdi child...
mdiChildForm.MdiParent = sender as Form;
}

[STAThread]
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new MainForm());
}
}
}

I'd like a simple fix but unfortunately I think it's truly a bug. One that's
unfortunately killing my schedule. If I'm doing something fundamentally
wrong I'd like to know.

Robert Conde
 
Robert,

I'm pretty sure you're not supposed to have more than one MdiContainer
form. I first heard this in VB6 days, but I haven't heard of it
changing either.
 
Well, I know you can't nest them - but I don't see why you shouldn't have
two top level forms. Anyhow it breaks even if I first set the mdiparent to
null, then turn off the IsMdiContainer of the first form, then turn on the
IsMdiContainer of the second form, then set the mdiparent to the second
form. So then at any one time there is only one mdi form. So either way...

Rob
 
Back
Top