Component vs. Control

后端 未结 4 983
一生所求
一生所求 2021-02-20 08:46

In the world of WinForms .Net controls

What is the difference between Component and Control?

  • Can a Control contains any Component?
  • Can a Compone
相关标签:
4条回答
  • 2021-02-20 09:28

    A Component is just a representation of an object/sub API. eg. ImageList is a component which is invisible and is just an API into a set of images. The fact you can drag and drop them onto forms is just sugar in the designer.

    A Control is intended to be visible/interactable/nestable.

    0 讨论(0)
  • 2021-02-20 09:35

    A Control has all the plumbing required to act as a window. The ability to respond to Window messages (WndProc) and having a Handle being foremost. Component is missing all that. It is really rather simple, it has design time support to set properties and it can be disposed, that's all.

    Components still can have a runtime representation, OpenFileDialog being the best example. But that is actually a dialog built into Windows, not Windows Forms.

    0 讨论(0)
  • 2021-02-20 09:40

    In response to your comment, the Component and Control can be seen in the Object browser as being from different object hierarchies. A Component cannot be added within a Control, as the Controls collection only accepts objects with base type of Control.

    A Component cannot contain Controls.

    0 讨论(0)
  • 2021-02-20 09:51

    A component is basically a class (it can be a dll, Activex Object).

    • It does not have User Interface capabilities that's why you cannot see a visual representation.
    • It is portable and not specific to any language.

    While on the other hand control is component which provides User Interface capabilities.

    • Since control has UI, you can see its visual representation.
    • It is language specific and not portable.
    0 讨论(0)
提交回复
热议问题