Sorry I didn't find a place to post the code but
I found a workaround! (Yay) I'll ask our Microsoft guy later, since I keep thinking shouldn't be this hard, but for now this will have to do.
I fake the thing out by setting the MdiParent to another MdiContainer Form, which acts as the Child's border.
That way
MdiParent = null never happens and no flags or event wiring are lost.
Here's the fixed up child form code:
public partial class ChildForm : Form {
Form mParent;
Form mFosterParent;
public ChildForm() {
InitializeComponent();
}
private void ChildForm_Load(object sender, EventArgs e) {
mParent = this.MdiParent;
}
private void PopOut_Click(object sender, EventArgs e) {
mFosterParent = new MDIParent2();
mFosterParent.Show();
mFosterParent.Text = this.Text;
mFosterParent.Width = this.Width + 4;
mFosterParent.Height = this.Height + 4;
MdiParent = mFosterParent;
this.Top = 0; this.Left = 0;
this.FormBorderStyle = FormBorderStyle.None;
}
private void PopIn_Click(object sender, EventArgs e) {
this.FormBorderStyle = FormBorderStyle.Sizable;
this.WindowState = FormWindowState.Normal;
MdiParent = mParent;
MdiParent = mParent; // Apparently I have to do this twice
mFosterParent.Close();
mFosterParent = null;
}
}
//I also had to modify the MdiContainer Resize event to make it look like one form
private void MDIParent2_Resize(object sender, EventArgs e) {
if (MdiChildren.Length > 0) {
this.MdiChildren[0].Height = this.Height - 38;
this.MdiChildren[0].Width = this.Width - 12;
}
}