views:

426

answers:

2

These are three different things you can add to a project and I am not quite sure if I understand the difference. They all seem to for example show up in the component toolbox when working with a Form. What are some common usage scenarios for each of them? What is the difference?

+10  A: 

The main difference between User Control, Custom Control and Component is that they inherit from different levels in the inheritance tree:

MyComponent
   |-> Component

MyCustomControl
   |-> Control
          |-> Component

MyUserControl
   |-> ContainerControl
          |-> ScrollableControl
                 |-> Control
                        |-> Component

So, in short you get a different amount of pre-wired functionality with the different options.

When would you use the different options? (these are thoughts and opinions, not truths)

  • Create a component if you want to provide functionality without UI (such as Timer components, data sources, ...)
  • Create a custom control if you want to make a component where you have full control over its visual appearance, and you don't want any baggage of unnecessary functionality. Typical cases would be simple controls with limited functionality (such as a button)
  • Create a user control if you are going to combine existing controls into reusable building blocks (such as two lists with buttons where you can move items between the lists).
Fredrik Mörk
+2  A: 

Adding to what Fredrik said, generally components and custom controls would be used when you plan on reusing them across projects. Use user controls when you would only be using it in one project.

Chad