Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

C# Change Form to MDI Child and back again

Posted on 2009-06-30
1
Medium Priority
?
967 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Introduction This article series is supposed to shed some light on the use of IDisposable and objects that inherit from it. In essence, a more apt title for this article would be: using (IDisposable) {}. I’m just not sure how many people would ge…
Hello there! As a developer I have modified and refactored the unit tests which was written by fellow developers in the past. On the course, I have gone through various misconceptions and technical challenges when it comes to implementation. I would…
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…
Look below the covers at a subform control , and the form that is inside it. Explore properties and see how easy it is to aggregate, get statistics, and synchronize results for your data. A Microsoft Access subform is used to show relevant calcul…

824 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