Marcus Davies
Marcus Davies

Reputation: 248

Change c# form design without creating an instance of such form

So... I have a requirement to build a plugin architecture for an app I am working on, the plugin architecture is actually built using interfaces, and generally works well.

One unique problem I am faced with is allowing a plugin to change the design of a form(s), for argument sake, adding further controls.

The plugin in this example is loaded during an onload event for the main host form.

Now then, can I somehow change any target form in the application and add extra controls without having to create an instance of such form, meaning ui modifications are already done before an instance is created.

I'm thinking searching the application for my target form using reflection and..... This is where I am stumped, how do I change found form, and have the edits available for any new instance?

Upvotes: 2

Views: 184

Answers (2)

Matin Lotfaliee
Matin Lotfaliee

Reputation: 1615

You can do this by inheritance.

Assume your form in the plugin is named pluginForm. In your application you need to create a form inherited from pluginForm instead of System.Windows.Form.

The designer will also work. Controls are locked unless you change the modifiers to Protected.

Upvotes: 2

We Are All Monica
We Are All Monica

Reputation: 13344

Have the plugins write to a list of controls that should appear on a given form, then have the form class read from that list when an instance is created.

Upvotes: 2

Related Questions