Solved

C# Change Form to MDI Child and back again

Posted on 2009-06-30
1
900 Views
Last Modified: 2012-05-07
I'm writing an MDI application with a lot of MDI child forms. I'm trying to add  the ability to change the forms from an MDI child to a floating form and back again. So far I've managed to change them to floating forms, but when I try to change them back to MDI children, I get the following exception when calling Form.Show():

An unhandled exception of type 'System.ComponentModel.Win32Exception' occurred in System.Windows.Forms.dll

Additional information: Error creating window handle.

Note: The property 'ContainerForm' references an MDIContainer form.
I've already tried the pinvoke SetParent method, but this prevents my toolstrips from working. and you lose the vista windows transparency effects.

Thanks
if (bConfined && this.MdiParent == null)
            {
                this.Hide();
                this.ContainerForm.RemoveOwnedForm(this);
                this.MdiParent = this.ContainerForm;
                this.Show();  //   <-- Exception occurs here
            }
            else if (!bConfined && this.MdiParent != null)
            {
                this.Hide();
                this.MdiParent = null;
                this.Show(this.ContainerForm);
                // SetParent(this.Handle, this.ContainerForm.Handle);
            }

Open in new window

0
Comment
Question by:ttnetworks
1 Comment
 

Accepted Solution

by:
ttnetworks earned 0 total points
ID: 24745220
Solved!

            if (bConfined && this.MdiParent == null)
            {
                this.Hide();
                this.Owner = null;
                this.Show();                
                this.MdiParent = this.ContainerForm;                
            }
            else if (!bConfined && this.MdiParent != null)
            {
                this.Hide();
                this.MdiParent = null;                
                this.Owner = this.ContainerForm;
                this.Show();
            }
0

Featured Post

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Article by: Ivo
C# And Nullable Types Since 2.0 C# has Nullable(T) Generic Structure. The idea behind is to allow value type objects to have null values just like reference types have. This concerns scenarios where not all data sources have values (like a databa…
This article describes a simple method to resize a control at runtime.  It includes ready-to-use source code and a complete sample demonstration application.  We'll also talk about C# Extension Methods. Introduction In one of my applications…
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…

831 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question