VFP Tutorial - Form Designer
As with any other Windows development tool, 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 tab of the Project
Manager then right-click on . Select
then
from the dialog.
The Form Designer will appear:
The screen shot shows the Form Designer and the Form Controls toolbar with
the mouse positioned above the Button control so that its tooltip is displayed.
Add data
The form has to be connected to a data table. Right-click on the form and
select
.
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:
Use the mouse to select the six fields from the Data Environment and drag
them to the form. If you do this with a normal left-click then FoxPro will
automatically create a grid control for the fields. Start the drag with a
right-click instead. Note that the tooltip will show you the size and type
of the field as you select it.
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
option. Make sure that you move the mouse to the top-left corner of the
form before you drop the fields. Some of the fields are quite wide and you
might have to make the form a bit larger to accept them it. 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
There are three ways of running the form. You can:
-
Click the red exclamation mark on the toolbar
-
Select from the
menu
-
Use the keyboard shortcut
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 the same as the form name. The form name is a property
of the form.
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. Use the cursor keys for
fine adjustments. Each key will nudge the control one pixel in the
appropriate direction. Hold down
and use the cursor keys to stretch or shrink the control by one pixel at a
time.
The 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.
Introduction to FoxPro |
Environment |
Project |
Tables |
Forms |
Navigation |
Executable
|