When to add a Component Class vs User Control?

后端 未结 4 1484
面向向阳花
面向向阳花 2021-02-04 00:00

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 cre

4条回答
  •  一整个雨季
    2021-02-04 00:27

    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 impelemnt 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.

提交回复
热议问题