Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can you load a .Net form as a control?

Tags:

.net

winforms

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?

like image 761
Keith Avatar asked Sep 09 '08 08:09

Keith


People also ask

How do I create a control over form?

Add the control by drawingSelect the control by clicking on it. In your form, drag-select a region. The control will be placed to fit the size of the region you selected.

What is form control in C#?

Forms namespace contains a large family of controls that add both form and function to a Windows-based user interface. Each control inherits a common set of members from the Control class. To these, it adds the methods, properties, and events that give the control its own distinctive behavior and appearance.

Is C# a control?

What is Control in c# programming Language? C# Control Windows Forms controls are reusable components that encapsulate user interface functionality and are used in client-side Windows applications. A button is a control, which is an interactive component that enables users to communicate with an application.


1 Answers

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 );
like image 186
Andrew Avatar answered Sep 30 '22 11:09

Andrew