tags:

views:

307

answers:

3

I want to load a desktop application, via reflection, as a Control inside another application.

The application I'm reflecting is a legacy one - I can't make changes to it.

I can dynamically access the Form, but can't load it as a Control.

In .Net Form expands on Control, and I can assign the reflected Form as a Control, but it throws a run-time exception.

Forms cannot be loaded as controls.

Is there any way to convert the form to a control?

+1  A: 

You should be able to add the form to the controls collection of your parent form...

See here: http://vbcity.com/forums/topic.asp?tid=30539

If that fails, try using the adapter pattern to create a container with your legacy form inside it, then load it in an MDI maybe?

Rob Stevenson-Leggett
+6  A: 

Yes, this works just fine. I'm working on a .NET app right now that loads forms into a panel on a host form.

The relevant snippet:

// setup the new form
form.TopLevel = false;
form.FormBorderStyle = FormBorderStyle.None;
form.Dock = DockStyle.Fill;
form.Show ( );

// add to the panel's list of child controls
panelFormHost.Controls.Add ( form );
Andrew
Tested and this works.Thanks :-)
Keith
+1  A: 

What is the exception you get? Is it possible that the control itself is giving the exception (vs the framework)? Perhaps something is called in the original applications Main function that is not being called?

dan gibson
I was getting a error related to the TopLevel property, something I couldn't set on a control, but could on a form.
Keith