.NET - MDI - Container - (Internet Explorer) ActiveX loses parent


Wim Verbeke

Hi everyone,

We are currently developing an application in C# which has MDI forms. Each
MDI form has a detach-button which removes the form from its parent and
displays it as a regular form.
In .NET, you can use the System.Windows.Forms.Form.MdiParent property.
Everything seems to work when regular .NET controls are part of the MDI

However, if there's an ActiveX control on the form, it loses its parent and
gets drawn somewhere on the screen, floating, not part of the MDI parent and
not part of the MDI form. This is the case with for example the Internet
Explorer ActiveX (shdocvw), the Remote Desktop ActiveX (msrdp) and probably
a lot of others. We did not have that problem with a third-party component,
which seems to remember its direct parent. I guess we forgot something in
the approach on how to handle the microsoft ActiveXs.

Has anybody a clue for this problem? We already checked every property of
the AxHost and Form (container, toplevelcontrol, toplevel, parent, ...) but
they're all updated correctly after the detach. We also tried to toy with
the SetChildIndex function...

Here are the important snippets of a sample application, full source upon

Project consists of 2 forms, MainForm (the MDI parent) and ChildForm (the
MDI child).

--- MainForm Load event : Start ---
this.IsMdiContainer = true;

ChildForm child = new ChildForm();

child.MdiParent = this;
child.ShowInTaskbar = false;

--- MainForm Load event : Stop ---

ChildForm has one button (DetachButton) and an Internet Explorer ActiveX
(Microsoft Web Browser from the Microsoft Internet Controls)

--- ChildForm : DetachButton event : Start ---
private void DetachButton_Click(object sender, System.EventArgs e)
this.MdiParent = null;
this.ShowInTaskbar = true;
--- ChildForm : DetachButton event : Stop ---

--- ChildForm : Public method : Start ---
public void ChangeUrl()
--- ChildForm : Public method : Stop ---

Run the application and the MDI form will show the microsoft-website. Click
detach and the form will be detached from its parent. The ActiveX starts
floating and is not part of the ChildForm anymore.

Thanks for your time!

Wim Verbeke



Carl Thomas


I've never used the WebBrowser control, so I'm not sure how you set its
parent or location when you do the layout initially, but changing the parent
in your DetachButton_Click handler looks like the thing to do. Since the
IWebBrowser2 interface has Left and Top properties to set, you could also
check that out.

Note also that ,NET Framework 2.0 has a WindowsForms port of the WebBrowser
control if you want to jump ahead and design for that. It's in the WinFX
May CTP.


Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question