VFP Tutorial - Form Designer

As with any other Windows application, the form is the basic interface for the user in Visual FoxPro.

FoxPro has a Form Wizard which will produce a good-looking form very quickly but the design relies on a number of complex class libraries and is difficult to understand or modify. We will build a straightforward form by hand.

Create a form

Click on the Documents tab of the Project Manager then right-click on Forms. Select New File then New Form from the dialog.

The Visual FoxPro Form Designer will appear. This screen shot is from VFP 9 but its appearance hasn't changed since VFP 3.

[VFP Form Designer]

The screen shot shows the Form Designer and the Form Controls toolbar with the mouse positioned above the Button control.

Add data

The form has to be connected to the data table that holds the information to be displayed. Right-click on the background of the form and select Data Environment ... from the shortcut menu. A directory tree will open so that you can select a table. Click on CD.dbf then close the Add Table dialog. This should leave you with the form and the Data Environment windows visible:

[Visual FoxPro Form Designer]

Use the mouse to select the six fields from the Data Environment and drag them to the form. If you select all six fields at once and drag with a normal left-click then FoxPro will automatically create a grid control for the fields. You have to start the drag with a right-click instead to override this.

When you drop the files a menu will appear with the option of showing the fields as a grid or as multiple controls. Select the Create Multiple Controls Here option. Make sure that you move the mouse to the top-left corner of the form before you drop the fields so that all will fit into the form. Some of the fields are quite wide and you might have to make the form a bit larger to accept them them. Just click on the form border and drag it to the size you want.

Close the Data Environment and leave the Form Designer on screen.

Run the form

[Simple VFP form] There are three ways of running the form. You can either:

  • Click the red exclamation mark on the toolbar,
  • Select Run Form from the Form option on the main menu,
  • Use the keyboard shortcut CTRL+E

You will be asked to save the form before you can run it. FoxPro will suggest a name something like 'Form1.Scx'. Change this to 'MyCD.scx' or something more suitable but do not change the file extension. Form data in Visual FoxPro is stored in a pair of files with 'scx' and 'sct' extensions. The 'scx' file is actually in VFP dbf format and the 'sct' file holds its memo fields in fpt format.

Note that the file name is not necessarily the same as the form name. The form name is a property of the form, the file name is the name of the file.

Moving and adjusting the size of controls

The obvious way to do this is to drag with the mouse and this is the fastest technique for making crude adjustments. You can also use the cursor keys for fine adjustments. Each key will nudge the control one pixel in the appropriate direction. Hold down shift and use the cursor keys to stretch or shrink the control by one pixel at a time.

The Format menu has options to align and size groups of controls. You can select multiple controls by shift-clicking on the controls one-by-one or by dragging a selection marquee around the group of controls. The selection marquee does not have to surround a control, it will select any control that it touches.

Improve the appearance of the form

The form will appear on screen and show the first record in the table but that's all that it will do. It also needs a lot of work on its cosmetic appearance. The captions are all at default values and the colour is just the basic Microsoft grey. All these can be improved by altering the properties of the form and controls. Properties are covered in the next page of this tutorial.


Introduction to Visual FoxPro | Environment | Project | Tables | Forms | Navigation | Executable

MS Access technical tips

Visual FoxPro technical tips

General Tips

 

More tips from Alvechurch Data

Visual FoxPro Tutorial - The Goto statement

The truth about the FoxPro Goto statement

Read More

Visual FoxPro Tutorial - If ... Else ... EndIf

Using If and EndIf to control program flow in Visual FoxPro

Read More

Visual FoxPro Tutorial - Navigation

Navigating between records in Visual FoxPro tables.

Read More

Visual FoxPro Tutorial - Scan ... EndScan loop

Using a scan loop to control program flow in Visual FoxPro.

Read More

Visual FoxPro Tutorial - Variables

Using variables in Visual FoxPro.

Read More