Remember when a friend wanted his VFP program to run this way: There is no VFP main screen (_screen), the runtime directly on the desktop, a login dialog box, enter the user name and password and verify the software after the main interface, looks like the software written in VB, a very cool feeling.
The main interface of VFP software can usually be implemented in two ways: the main screen (_screen) or the top-level form (or the parent-child form). You can use the top level form to implement the above ideas.
The way to set up the top-level form in VFP is to set the ShowWindow property of the form to "2-as the top-level form", this is the so-called "parent form", and for that, you need to set the ShowWindow property of the subform to 1-in the top-level form. This article is a small example of a top-level form, which is a "warm-up". In the future, we will give an example of using the top-level form to implement the main interface of the software, and, of course, the main screen (_screen) to implement the main interface of the software.
This example uses the "Site information table" in database "Data 1" as the data source for the form's data environment, and the case of the database is already looking at the example of VFP: A sample database is given in the article. When you run this example, start the parent form. SCX, which displays the first record of the site information table, as shown in figure I below;
Figure I
When you click the Start Child Form button on the parent form, the command button is disabled while the subform is started (the command button is automatically activated when the child form is closed); When the subform is started, when you click the command buttons on its first, next, and so on, the parent form updates the records that appear in the Site information table. You can move a child form by pointing to the title bar of the child form, but it moves within the parent form window, as shown in Figure 2:
Figure II
This example makes the following steps:
Create a new form Form1, set its properties on the following table, and save it as a "parent form. Scx":
Property name |
Property value |
Caption |
Parent form |
AutoCenter |
. T. |
Width |
375 |
Height |
130 |
ShowWindow |
2-as the top level form |
Add a command button Command1 to the parent form, set its Caption property value to start child form, resize it appropriately, and then add a Label control, and set the label's properties in the following table:
Property name |
Property value |
Caption |
Parent-child form relationships |
AutoSize |
. T. |
FontBold |
. T. |
FontSize |
16 |
ForeColor |
0,0,255 |
Third, right click on the parent form blank Select the Data Environment command to add the site information table to the data environment. In the Data Environment Designer, drag the field names from the Site information table to the parent form (NOTE: This example does not drag the title bar, otherwise it generates a table, adjusts the size of the resulting control and the position of the controls within the parent form, and the adjusted form looks like this:
Add the event code for the parent form and the controls it contains:
(1) Unload event for parent form: close data
(2) command button Command1 Click event Code:
This.enabled=.f.
Do form child form
After the parent form is set, the parent form is closed, then a new form is created, the properties are set by the following table, and the SCX is saved as a child form. SCX:
Property name |
Property value |
Caption |
Child form |
ShowWindow |
1-In the top level form |
Six, add four command button Command1~command4 and a spinner button (Spinner) control to the child form, set the Caption property of the four command buttons to "first", "previous", "Next" and "last", Then line up four buttons and spinner controls, and lower the width and height of the subform so that it looks like a toolbar, as shown in the following figure:
Set the properties of the fine-tuning button Spinner1 according to the following table:
Property name |
Property value |
Spinnerhighvalue |
=reccount () |
Spinnerlowvalue |
1.00 |
Eight, add event code for the child form and the controls it contains:
(1) QueryUnload event for the child form:
The parent form. command1.enabled=.t && function is to activate the Start Child form button on the parent form when the child form closes
(2) Click event for "First" button (Command1):
If BOF () =.f.
Go top
endif
parent form. Refresh
(3) Click event for the previous button (Command2):
If BOF () =.f.
Skip-1
endif
parent form. Refresh
(4) Click event for the Next button (Command3):
If EOF () =.f.
Skip
endif
parent form. Refresh
(5) Click event for "Last" button (COMMAND4):
If EOF () =.f.
Go Bottom
endif
parent form. Refresh
(6) Fine-tuning button Spinner1 Interactivechange event code:
S=this.value
Goto S
Parent form. Refresh
Run "parent form. Scx", you can get the effect of this example.
This example code is debugged in the win2003+vfp6.0 environment.
See the full set of "rookie also learn VFP" tutorial