This example makes a simple login form, the system runs when the first launch of this login form, run the interface as shown below:
Enter the correct username and password to start the main form, as shown below, if the user name and password entered incorrectly 3 consecutive times will automatically exit.
The production steps are as follows:
A new form, set the Caption property value of the form to system login, the ShowWindow property value is set to 2-as the top-level form, and the Width property value is set to the 295,height property value set to the 100,autocenter property value set to, and save the form as "system login. Scx".
Second, continue to set the form's properties: The Maxbutton and Minbutton property values for the form are set to. F, which masks the form's maximized and minimized buttons, and becomes a dialog box with only one close button.
Add two label controls to the form and set their Caption property values to user name and password respectively.
Add two text box controls to the form and set the TEXT2 's PasswordChar property value to "*".
Five, add two command buttons to the form Command1 and Command2, and set their Caption property values to OK and exit respectively.
Adjust the position and size of each control on the form and adjust the form designer as shown below:
Right-click the blank space in the form, select the Data Environment command, and add the administration table to the form's data environment.
Eight, add the event code:
(i) Init event code for the form:
Public CN && declaring global variables to calculate the number of logins
Cn=0
(ii) Unload events of the form:
Close all
Clear Events
Quit
(iii) The KeyPress event code that receives the user name text box Text1:
Lparameters Nkeycode, Nshiftaltctrl
if nkeycode=13.and.! Empty (this.value) && Enter the username and press ENTER to enter the password
thisform. text2.enabled=.t.
Thisform. Text2.setfocus
endif
(iv) The Click event code for the "OK" button Command1:
Cname=alltrim (Thisform.text1.value)
Ppassword=alltrim (thisform.text2.value)
cn=cn+1
if cn=3
Thisform.release
endif
set exact on Go top locate for
operator name =cname.and. password =ppassword
if EOF ()
MessageBox (' username or password is wrong, please re-enter! ', ' system hint ' return
else
thisform.visible=.f.
Do form master Form && incoming main interface form
endif
set exact off && set word Fu Fei exact comparison
(v) "Exit" button Command2 Click event Code: Thisform.release
Nine, run "system login. Scx" Can, in looking at the example of VFP: sample database in the article has given the "management. DBF" structure, where the preset two operator username and password are:
User name |
Password |
Tom |
12345678 |
John doe |
Aaaaaaaa |
This example code is debugged in the win2003+vfp6.0 environment.
See the full set of "rookie also learn VFP" tutorial