Customizing Template Behavior

[Previous] [Next]

If you don't use object templates when developing, you can streamline the development process a bit by turning off specific object templates. Suppose, for example, that you want to add a form to a project. If form templates are enabled, Visual Basic displays an Add Form dialog box like the one shown in Figure 2-5, and you have to select a particular type of form, even if you just want to add a standard form. However, you can eliminate this step by disabling form templates. Similarly, you can eliminate the appearance of the Add <object> dialog box for other types of objects.

click to view at full size.

Figure 2-5. If you don't use templates, the Add<object> dialog box can add an unnecessary step to your development process.

Enabling and Disabling Templates

To disable templates for an object type, display Visual Basic's Options dialog box by choosing Options from the Tools menu and then click the Environment tab. (See Figure 2-6.) If you don't want to use templates of a certain type, clear the appropriate check box. When the templates are disabled for a type, adding an object of that type causes a new standard object of that type to be added to the project, without the intermediate step of the Add <object> dialog box appearing.

click to view at full size.

Figure 2-6. You can pick and choose what types of templates to enable or disable.

Setting the Templates Folder

You can add another level of consistency to your team development environment by specifying a custom template folder. The folder specified in the Templates Directory text box on the Environment tab of the Options dialog box ”take a look at Figure 2-6 again ”is the parent folder in which Visual Basic looks for object templates. For example, when you have enabled templates and you choose Add Form from the Project menu, Visual Basic looks in the specified folder for a subfolder named Forms and then adds all the form files it finds there to the dialog box.

To create your own custom template folder, you must create a root folder (that is, the folder you specify in the Templates Directory text box) as well as the proper subfolders . To simplify the process, just copy the Template folder in your Visual Basic folder to a shared drive, remove the templates you don't want to use, and set the path in the Templates Directory text box to the new folder you've created. Then place all your company's object templates in this custom template folder and have all the developers enter the path to the new folder in their Templates Directory text boxes. Whenever a developer adds a template object to a project, he or she will be using the same template as everyone else.

Goals of Using Object and Project Templates

The primary goals of using object and project templates include

  • Promoting and encouraging code reuse
  • Reducing development time of new and existing projects


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