Click here to Skip to main content
14,976,254 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Some times we use component class in our applications. Why this component class is used? Does it have any advantages?

When I added component class to my application,I could find only two links over it toolbox and click here to switch code view, when I select any tool it is displayed on my component sheet and I could run this file but the tools i added on my component designer is not visible in my output.
Updated 8-Oct-10 23:36pm

I don't know what the last parapgraph of your question means, but as far as I know, the component class allows you to create an object that can be dragged onto the VS design surface and therefore be part of your component tray.

The advantages are that the code to create the component are handled in the designer.cs file and do not have to be considered by you when you are writting code except for setting up the object's properties etc.

An example could be a SerialPort object. You can drag and drop it onto the designer surface and then the SerialPort comms = new SerialPort(); happens in designer and you don't have to worry about explicitly doing it in code.

The main advantage for components (as far as I know) is when you get to things like Controls that can be added and placed on the form without having to set up location properties manually, etc.

Hope this gives some clarification :)

A class deriving from Component can be used in design mode for setting properties, hooking up event handlers etc even though it will have no visibility, unless you implement that side of it yourself but then it'd be easier to use Control as a base.
This doesn't sound like much of an advantage but it today's drag and drop programming world it makes sense.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900