Using Object Templates

[Previous] [ Next ]

When you choose to add a new object to a project, Microsoft Visual Basic displays a dialog box (for example, the Add Form dialog box) from which you can select an existing object or create a new object (either a generic object or an object based on a template). (See Figure 2-1.) Although Visual Basic ships with a number of predefined object templates (most notably a number of form templates), you aren't limited to just those that are provided. Any standard object (for example, a form or a module) you create and save in Visual Basic can be made into an object template.

click to view at full size.

Figure 2-1. The Add Form dialog box displays the form templates contained in the Template\Forms folder.

When Visual Basic displays an Add <object> dialog box with a number of object template icons, as shown in Figure 2-1, those object templates aren't displayed from a static list. Instead, Visual Basic looks at the Template folder located in the main Visual Basic folder. Within the Template folder are a number of subfolders , one for each type of object that can have templates. (See Figure 2-2.) Visual Basic looks within the appropriate subfolder and adds each of the objects within that subfolder to the Add <object> dialog box as a template icon. If a file placed within a subfolder isn't of the correct type, it's ignored.

click to view at full size.

Figure 2-2. The Template folder contains subfolders for the various objects that can have templates.

Suppose for instance that you've created a form object, and you want it to appear in the Add Form dialog box each time you choose Add Form from the Project menu. Simply place a copy of your form file in the Forms subfolder of the Template folder. If the form has a binary file associated with it (that is, an .frx file), that file must also be placed in the subfolder. To prevent an object from appearing as a template, delete or move the object's files from the appropriate subfolder of the Template folder.

When a template object is added to a project, a new instance of that object is created; changes made to the object are not propagated to the template itself. When you save the project, Visual Basic prompts you for a filename and path for the object. The next time an object is created based on that template, the template will be the same as it was originally.

NOTE
To make changes to an object template, add the object to a project by using the Existing tab of the Add <object> dialog box, make your changes, and save the object.


Practical Standards for Microsoft Visual Basic
Practical Standards for Microsoft Visual Basic .NET (Pro-Developer)
ISBN: 0735613567
EAN: 2147483647
Year: 2000
Pages: 57

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