Solved

C# Change Form to MDI Child and back again

Posted on 2009-06-30
1
927 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
[X]
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
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

Industry Leaders: 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

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…
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…
There are cases when e.g. an IT administrator wants to have full access and view into selected mailboxes on Exchange server, directly from his own email account in Outlook or Outlook Web Access. This proves useful when for example administrator want…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …

734 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