Passing parameters to a user control

jrvbdeveloper

Member
Joined
Jul 15, 2007
Messages
17
Programming Experience
Beginner
Hi,

Is there any way to pass parameters to a user control, *and* have it available in the toolbar to drag and drop onto a form? i.e. I'd like the constructor for the user control to have some parameters, however, this causes me a problem when I try to drag and drop the user control onto a windows form.

Thanks in advance.

Omar
 
When you add a control to a form in the designer the IDE invokes its constructor with no arguments. As long as the control has a constructor with no arguments you can use it in the designer. You can also overload the constructor, which allows you to add other constructors that do have arguments. You can then create instances of the control in code and pass parameters to the constructor. That said, it's a rare thing to have a control whose constructor has arguments. You can't enforce them because you've always got to provide a constructor with no arguments anyway. I suggest that you just stick to the norm and set the object's properties after creating it with no arguments.
 
Back
Top