Authoring Controls for Windows Forms
A control represents a graphical link between the user and the program. A control can provide or process data, accept user input, respond to events, or perform any number of other functions that connect the user and the application. Because a control is essentially a component with a graphical interface, it can serve any function that a component does, as well as providing user interaction. Controls are created to serve specific purposes, and authoring controls is just another programming task. With that in mind, the following steps represent an overview of the control authoring process. Links provide additional information on the individual steps.
Note If you want to author a custom control to use on Web Forms, see Developing ASP.NET Server Controls.
To author a control
- Determine what you want your control to accomplish, or what part it will play in your application. Factors to consider are:
- What kind of graphical interface do I need?
- What specific user interactions will this control handle?
- Is the functionality I need approached by any existing controls?
- Can I get the functionality I need by combining several Windows Forms controls?
- If you need an object model for your control, determine how functionality will be distributed throughout the object model, and divide up functionality between the control and any subobjects. An object model may be useful if you are planning a complex control, or wish to incorporate several functionalities.
- Determine the type of control (for example, user control, custom control, inherited Windows Forms control) you need. For details, see Control Type Recommendations.
- Express functionality as properties, methods, and events of the control and its subobjects or subsidiary structures, and assign appropriate access levels (public, protected, and so on). For more information, see Properties, Methods, and Events for Custom Controls.
- If you need custom painting for your control, add code for it. For details, see Custom Control Painting and Rendering.
- Create a new project (such as a Windows Application) so that you can test and debug your control.
Another project is required because controls cannot be run as stand-alone projects. They must be placed into a container before they can be tested. This process is demonstrated as part of Walkthrough: Authoring a User Control With Visual Basic .NET.
- As you add each feature, add features to your test project to exercise the new functionality.
- Repeat, refining the design.
- Package and deploy your control. For details, see Merge Module Projects.
Walkthrough: Authoring a User Control With Visual Basic .NET | Walkthrough: Inheriting from a Windows Forms Control with Visual Basic .NET | Authoring Controls for Windows Forms | Inheriting from the UserControl Class | Inheriting from the Control Class | Inheriting from Existing Windows Forms Controls