Creating a Component

The controls demonstrated so far have been visual; they have a size and a position on the screen. Not all controls have position on the designer surface. Consider the Timer and MainMenu controls from the toolbox. You can create custom controls of this kind by basing your control on the Component class rather than on the Control class or a specific toolbox class such as TextBox. The Component class is simpler than Control: it provides an implementation of the IComponent interface, which works alongside the ISite interface provided by a container class such as a form.

The following code is a simple component called CalcComponent that adds and subtracts integers with Add and Subtract methods. Clearly, it is not sophisticated, ...

Get Microsoft® .NET Compact Framework (Core Reference) now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.