Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

C# Change Form to MDI Child and back again

Posted on 2009-06-30
1
904 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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Where did System.Data.Objects go? 2 40
C# bracket error 3 35
Create a WebAPI using a generic return parameter 9 30
C# Formatting DateTime String Value 5 27
Extention Methods in C# 3.0 by Ivo Stoykov C# 3.0 offers extension methods. They allow extending existing classes without changing the class's source code or relying on inheritance. These are static methods invoked as instance method. This…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

808 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