Partager via


Setting Form Templates

You can create your own form class to use a template for all your new forms, or you can use one of the sample classes that ship with Visual FoxPro.

When you create a new form, it is based on the template form that is set in the Options dialog box. If no template is specified, the new form is based on the Visual FoxPro Form base class. For more information about Visual FoxPro classes, see Object-Oriented Programming.

Advantages of Using Form Templates

Form templates allow you to set default properties for your forms so that you can easily give all the forms in your application a consistent look and feel. You could include a company logo, for instance, and use a consistent color scheme in all your forms by designing a template form class with these attributes. If the company logo changes, you could change the picture in the template form class and all the forms you created based on the template would automatically inherit the new logo.

You can add custom properties and methods to the Visual FoxPro form class so that these properties and methods are available to each form in your application. If you are used to creating variables and user-defined procedures that are scoped to a form, using custom properties and methods provides this functionality, and also allows you to have a cleaner encapsulation model.

Specifying the Default Form Template

You can specify a form class from a registered class library for your form template.

To specify a default form template

  1. From the Tools menu, choose Options.

  2. In the Options dialog box, choose the Forms tab.

  3. In the Template classes area, select the Form check box.

    If no form template has been selected, the Open dialog box opens so that you can choose a form class. If a form template has been selected, you can change it by choosing the dialog button and selecting another class.

  4. Choose Set as Default if you want the template to be used in subsequent sessions of Visual FoxPro.

  5. Choose OK.

Using Form Templates

You can specify form set templates the same way you set form templates. The following combinations are possible:

  • Both form set and form templates are specified.

    Choosing Form in the New dialog box (and all the other ways to create a new form) will automatically create a form set based on the template form set class. When you choose Add New Form from the Form menu in the Form Designer, a form based on your form template is added to the form set.

  • Only the form set template is specified.

    Choosing Form in the New dialog box (and all the other ways to create a new form) will automatically create a form set based on the template FormSet class. When you choose Add New Form from the Form menu in the Form Designer, a form based on the Visual FoxPro Form base class is added to the form set.

  • Only the form template is specified.

    Choosing Form in the New dialog box (and all the other ways to create a new form) will automatically create a form based on the template Form class.

  • No templates are specified.

    Choosing Form in the New dialog box (and all the other ways to create a new form) will automatically create a form based on the Visual FoxPro Form base class.

See Also

Creating Forms with Local and Remote Data | Creating Forms | Options | Saving a Form as HTML | Setting the Design Area for a Form | Managing Multiple Instances of a Form