The following example sets properties and calls event code from various objects within a form set. The example includes two forms, frmLeft and frmRight, in a formset.
The two check boxes and the command button on frmLeft have event code associated with them. The name of the text box on frmLeft is txtInput
.
Event Code for Objects in LeftForm
Object | Event | Code |
---|---|---|
chkItalic |
Click |
|
chkBold |
Click |
|
cmdClear |
Click |
|
Setting a Property of Another Control on the Same Form
You can set the properties of one control from within the event code of another by using the THISFORM keyword or the Parent property. The following two commands are executed when a user initially clicks on the Italic and the Bold check boxes, setting the appropriate text box properties:
В | Copy Code |
---|---|
THISFORM.txtInput.FontItalic = .T. THIS.Parent.txtInput.FontBold = .T. |
In this case, THISFORM and THIS.Parent can be used interchangeably.
The code in the click event for cmdClear
uses THISFORM to reset the values of the other controls on the form.
Setting Another Form's Properties
You can also set properties of one form from another. Form2 contains five command buttons. The first button on the form has this code in its Click event:
В | Copy Code |
---|---|
THISFORMSET.frmLeft.Caption = ; ALLTRIM(ThisFormSet.frmLeft.txtInput.Value) |
Notice that the form set and the form need to be referenced when setting properties from within a different form.
The click event code of the second command button on frmRight
demonstrates setting a property of a form from within an object on the form:
В | Copy Code |
---|---|
THISFORM.Caption = ; ALLTRIM(ThisFormSet.frmLeft.txtInput.Value) |
If the user chooses this button, the caption of frmRight changes to the value in the text box on frmLeft.
Accessing Objects on Different Forms
The following code in the Click event of the Change Bold Setting command button changes the value of the Bold check box on frmLeft and calls the event code associated with this control.
В | Copy Code |
---|---|
THISFORMSET.frmLeft.chkBold.Value = ; NOT THISFORMSET.frmLeft.chkBold.Value THISFORMSET.frmLeft.chkBold.InteractiveChange |
The last line of the example calls the InteractiveChange event of chkBold
. You could also call this procedure with the following command:
В | Copy Code |
---|---|
THISFORMSET.frmForm1.chkBold.InteractiveChange( ) |
If this procedure call is omitted, the value of the check box changes, but the FontBold property of the text box is never changed.
Checking Properties and Calling Method Code of Another Form
The following code in the Click event of the Hide Left Form command button hides or shows frmLeft, depending on the value of the Visible property, and changes the button caption as appropriate:
В | Copy Code |
---|---|
IF ThisFormSet.frmLeft.Visible ThisFormSet.frmLeft.Hide THIS.Caption = "Show Left Form" ELSE ThisFormSet.frmLeft.Show THIS.Caption = "Hide Left Form" ENDIF |
Notice that the THIS keyword is used within event code of a control to reference properties of the control.
The following command in the Click event of the Quit command button releases the form set, causing both forms to close:
В | Copy Code |
---|---|
RELEASE ThisFormSet |