Reputation: 155662
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?
Upvotes: 7
Views: 1151
Reputation: 3665
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?
Upvotes: 1
Reputation: 12009
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 );
Upvotes: 10
Reputation: 35679
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?
Upvotes: 1