Controls and Components in Executable Projects


Most of this chapter explains how to build a control library containing any number of controls and components. You can compile the library into a .dll file and use it in executable applications.

You can also build custom controls or components within an executable project. In that case, the controls or components are compiled into the executable rather than a separate .dll file, so you cannot use them in other applications. If these are very specialized objects that you probably won’t need to use in other applications, this is not a major disadvantage and saves you the trouble of installing an extra .dll file with the application.

UserControls in Executable Projects

To add a custom UserControl to a project, open the Project menu and select Add User Control. Leave the User Control template selected, enter a name for the control, and click Add. Add constituent controls to the UserControl as usual.

Initially, the control does not appear in the Toolbox, so you cannot use it on a form. Select the Build menu’s Build command to compile the control and the rest of the project. Visual Basic places the new control in a Toolbox section named after the project. If the project’s name is Billing, it places the control in a Toolbox section named Billing Components. Now you can use the control as usual.

Inherited UserControls in Executable Projects

To build a UserControl that inherits from an existing UserControl class, select the Project menu’s Add New Item command. In the resulting dialog, select the Inherited User Control template, enter a name for the control, and click Add. The Inheritance Picker dialog box shown in Figure 12-7 lists compiled components in the current project. Select the control from which you want to inherit and click OK.

image from book
Figure 12-7: Use the Inheritance Picker to make a control that inherits from an existing UserControl.

Add properties, methods, and events to the control as usual. Select the Build menu’s Build command to compile the control and add it to the Toolbox.

Alternatively, you can create a new class and add an Inherits statement that makes the class inherit from the previously built UserControl.

Controls in Executable Projects

To build a control that inherits from the Control class in an executable project, select the Project menu’s Add Class command. Leave the Class template selected, enter a name for the control, and click Add. Add the statement Inherits Control to the control’s code.

Add properties, methods, and events to the control as usual. For example, you may want to give the control Paint and Resize event handlers so that it can draw itself. You may also want to override the parent class’s behaviors.

Select the Build menu’s Build command to compile the control and add it to the Toolbox.

Inherited Controls in Executable Projects

To build a control that inherits from a predefined control, select the Project menu’s Add Class command. Leave the Class template selected, enter a name for the control, and click Add. Add an Inherits statement that makes the class inherit from the previously built control.

Add properties, methods, and events to the control as usual. For example, you may want to give the control Paint and Resize event handlers so that it can draw itself. You may also want to override the parent class’s behaviors.

Select the Build menu’s Build command to compile the control and add it to the Toolbox.

Components in Executable Projects

To add a component to an executable project, select the Project menu’s Add Component command. Leave the Component Class template selected, enter a name for the component, and click Add.

Add properties, methods, and events to the component as usual. Then select the Build menu’s Build command to compile the component and add it to the Toolbox.




Visual Basic 2005 with  .NET 3.0 Programmer's Reference
Visual Basic 2005 with .NET 3.0 Programmer's Reference
ISBN: 470137053
EAN: N/A
Year: 2007
Pages: 417

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net