Components


A component is basically a control with no visible component at runtime. Instead of appearing on the form at design time, a component appears in the component tray below the form. Figure 12-5 shows a form containing several components.

image from book
Figure 12-5: The form designer displays components in the component tray below the form.

You can select a component in the component tray and then view and modify its properties in the Properties window. In Figure 12-5, the FontDialog1 component is selected, so the Properties window is displaying that component’s properties.

Building a component is just as easy as building a control. To make a new component, open the Project menu and select Add Component. Leave the Component Class template selected, enter the name you want to give the component, and click OK.

Initially, Visual Basic displays the component as shown in Figure 12-6. To add instances of existing components to the new component, click and drag tools from Server Explorer or the Toolbox onto the new component.

image from book
Figure 12-6: You can add existing components to a new component.

If you click the Solution Explorer’s Show All Files button and then open the component’s designer-generated code file, you’ll see that the class inherits from the System.ComponentModel.Component class rather than from the System.Windows.Forms.Control class.

You can add properties, methods, and events to the component just as you would add them to a control. You can also use the same attributes to modify the component and its properties and events. For example, you can give the component a Toolbox bitmap, a default property and event, add descriptions to properties, and assign properties to categories. In addition to displaying the bitmap in the Toolbox, Visual Basic also displays it in the component tray below the form when you add an instance of the component to the form.




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