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
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