Visual Basic Concepts

Working with Templates

Visual Basic provides a variety of templates for creating common application components. Rather than creating all the pieces of your application from scratch, you can customize an existing template. You can also reuse custom components in multiple applications by creating your own templates.

You can open an existing template by selecting its icon in the Add Object dialog box when you create a new form, module, control, property page, or document. For example, Visual Basic provides built-in form templates for creating an About dialog box, Options dialog box, or splash screen.

Figure 8.3   The Add Form dialog box

When you open a template, Visual Basic displays the object with placeholders that you can customize. For example, to create an About dialog box, open the About Dialog template and replace the Application Title, Version, and App Description placeholders with information specific to your application.

Figure 8.4   The About Dialog form template

To create your own template, save the object that you want to use as a template, then copy it to the appropriate subdirectory of the Visual Basic Template directory. For example, to create a custom MyForm form template, save a form named MyForm, then copy the MyForm.frm file to the \VB\Template\Forms directory. When you select the Add Form command from the Project menu, Visual Basic displays the MyForm template in the Add Form dialog box, as shown in Figure 8.3.

You can disable display of templates in the Add object dialog box by selecting the Options command on the Tools menu and clearing the Show Templates options on the Environment tab of the Options dialog box. For example, to disable the display of form templates, clear the Forms option in the dialog box.

Figure 8.5   The Environment tab of the Options dialog box