Solved

C# Change Form to MDI Child and back again

Posted on 2009-06-30
1
878 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
Comment Utility
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

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

Introduction Although it is an old technology, serial ports are still being used by many hardware manufacturers. If you develop applications in C#, Microsoft .NET framework has SerialPort class to communicate with the serial ports.  I needed to…
Summary: Persistence is the capability of an application to store the state of objects and recover it when necessary. This article compares the two common types of serialization in aspects of data access, readability, and runtime cost. A ready-to…
This video discusses moving either the default database or any database to a new volume.
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

772 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now