Search code examples
c#winformscomponentsuser-controlscontrols

When to add a Component Class vs User Control?


I have a general idea, and there are some obvious cases, but there are also some gray areas for me - when is it best to use to extend from a component and when is it best to create a user control? This pertains to a specific work problem I am trying to solve, but the specifics of that are not important - a general answer to this question is enough for me.


Solution

  • In WPF and Windows Forms, both, the main difference is that a UserControl is meant to be a collection of controls - a reusable, single object "composed" from multiple controls themselves.

    You'd implement a Component/CustomControl/Control instead of a UserControl if you are making a single, primitive control with new behavior, instead of making a "control" that's composed of smaller controls.

    Component usually is a non-visual behavior, where a CustomControl/Control is usually for a visual control.