32

What is a component class and where would I typically use one?

When I add a new item to my project in VS.NET 2008 one of the options is to add a component. I am not even sure I understand what a component is - but I would sure like to find out a bit more about them.

Could somebody explain them to me or perhaps point me towards an online tutorial that would help me.

casperOne
  • 73,706
  • 19
  • 184
  • 253
Brad
  • 20,302
  • 36
  • 84
  • 102

3 Answers3

16

Well, generally speaking, a component is any part of a thing. Specifically in .NET, a component is a class that implements the IComponent interface, which indicates that a class can interact with it's logical container.

More often than not, you see this in the form of design support, in that classes interact with their host in the designer, but that's not a strict requirement.

casperOne
  • 73,706
  • 19
  • 184
  • 253
  • What is container? Is it possible to explain it in an intuitive way? To the best of my knowledge, container contains component. That's it. – Andes Lam Aug 14 '21 at 05:54
13

Component Class is for sharing objects between applications.

Typically for dropping down object like outlook email to an application.

belaz
  • 1,486
  • 5
  • 18
  • 33
6

If you mean a class that inherits from System.ComponentModel.Component, like for example the System.Windows.Forms.BindingSource and strongly-typed DataSets, this will allow to drag an instance on the Visual Studio design surface (on a form in design-time) and set some properties using the property grid.

Once there is an instance of such component on the form it is discoverable by other components/controls. For example a BindingSource can be selected as a data source for a grid view or some other control.

Jeff
  • 12,555
  • 5
  • 33
  • 60
Yordan Pavlov
  • 5,126
  • 4
  • 25
  • 15