Using Object Templates

When you choose to add a new object, such as a Windows Form, to a project, Microsoft Visual Basic .NET displays a dialog box from which you can select an existing object or create a new object. (See Figure 1-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 module or class) you create and save in Visual Basic can be made into an object template.

Figure 1-1. The Add New Item dialog box displays the templates available on the computer.

graphics/f01ln01.jpg

When Visual Basic displays an Add New Item dialog box with a number of object template icons, as shown in Figure 1-1, those object templates aren't displayed from a static list. Instead, Visual Basic looks at the \Microsoft Visual Studio .NET\Vb7\VBProjectItems\Local Project Items folder. Within this folder are a number of subfolders (\Code, \Data, \UI, \Utility, and \Web). These folders correspond to the same folders you see in the Add New Item dialog box when you expand the Local Project Items folder. (See Figure 1-2.) Any Visual Basic .NET object files placed within these folders appear in the Add New Dialog box.

Suppose for instance that you've created a form object, and you want it to appear in the Add New Item dialog box within the \UI folder. Simply place a copy of your form file in the \UI subfolder of the \Local Project Items folder. If the form has a binary file associated with it (that is, a .resx 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.

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 source template itself. When you save the project, Visual Basic .NET prompts you for a filename and path for the object. The next time an object is created based on the same template, the template will be as it was originally.

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

graphics/f01ln02.jpg

Note

To make changes to an object template, add the object to a project, make your changes and save the object in a temporary folder, and then copy the new object files to the appropriate template folder.



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

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