Maxime C.
Maxime C.

Reputation: 35

Is there away to drop a usercontrol with parameters into a form?

I have a usercontrol with a readonly parameter. Is there away to drop this usercontrol in winforms from toolbox (filling in the parameter of the constructor)?

I want to make my program as user friendly as possible. By this i mean when the "client" wants the designt to change he/she has to just drag and drop from the toolbox without going into the code. Now i'm creating and positioning the usercontrol in my class. I also could make diffrent usercontrols per enum and do it this way.

public partial class MyUserControl : UserControl{
     public MyUserControl(Enum type){}
}

Upvotes: 1

Views: 79

Answers (1)

Olivier Jacot-Descombes
Olivier Jacot-Descombes

Reputation: 112682

Make sure your control also has a default constructor, i.e. a constructor with no parameters. You can keep the current parametrized constructor if you intend to create controls in code. If you add a public property exposing your enum, then it will appear in the properties window of your control. Values you set there will be persisted, i.e., the form will remember this value.

If the user control is in the current project, once successfully compiled, the Toolbox Window will automatically list your control at the very top.

If the UserControl is in another project, you must edit the Toolbox and add a reference to the other assembly to add the controls to the Toolbox.

Upvotes: 1

Related Questions