Strange behavior when loading mdi winform c# .net
I´m getting a strange behavior in a c# MDI WinForms application. When i open a specific form together with any other form, this specific form locks up. Somehow its grouping the ControlBox of both forms into one, looking like this:
As the forms has stopped responding, its not closeable and has stopped painting:
The strange part is that any other combination of forms works fine. The forms gets loaded on top of each other and the application does not freeze. But i can not figure out whats different about this form compared to the others. All settings are identical. This is the code in the main MDIform that initiate new child forms, its called from a ToolStrip Button.Click event:
private void OpenForm(object sender)
{
if (sender == null) return;
ToolStripMenuItem itemSender = (ToolStripMenuItem)sender;
try
{
WinForm mapping = (WinForm)itemSender.Tag;
if (!FormList.ContainsKey(mapping.FormName))
{
Type frmType = Type.GetType(string.Format("OrderAssist.Forms.{0}", mapping.FormName));
if (frmType != null)
{
Form newForm = (Form)Activator.CreateInstance(frmType);
if (!newForm.IsDisposed)
{
newForm.Name = mapping.FormName;
newForm.Tag = itemSender;
newForm.MdiParent = this;
newForm.Show();
newForm.WindowState = System.Windows.Forms.FormWindowState.Maximized;
newForm.FormClosing += new Fo开发者_开发问答rmClosingEventHandler(newForm_FormClosing);
FormList.Add(newForm.Name, newForm);
itemSender.Checked = true;
newForm.Activate();
}
}
else
itemSender.Enabled = false;
}
else
FormList[mapping.FormName].Activate();
}
catch (Exception e)
{
Exceptions.ProgramException(e, Settings.User.ID, "Exception occured while opening a form.");
if (itemSender != null)
itemSender.Enabled = false;
}
}
To make the matter stranger, if i populate this form that locks with data and click on some controls inside, before opening another form, the error does not occur.
Im out of ideas of what to try next.
newForm.WindowState = System.Windows.Forms.FormWindowState.Maximized;
The above line is called for all your controls, which results in the control boxes being grouped together.
As for that form freezing up, you need to post the code of the child form that causes the form freeze. Then I can assist you further.
精彩评论