Component vs. Control

吃可爱长大的小学妹 提交于 2019-12-05 17:22:47

问题


In the world of WinForms .Net controls

What is the difference between Component and Control?

  • Can a Control contains any Component?
  • Can a Component contains any Control?

回答1:


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 and it can be disposed, that's about it.

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




回答2:


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.




回答3:


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.




回答4:


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.


来源:https://stackoverflow.com/questions/672730/component-vs-control

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!