Specifies whether an object is visible or hidden. Read/write at design time and run time.
Object.Visible [= lExpr] |
Return Value
- lExpr
-
Specifies a value that determines whether an object is visible or hidden.
The following table lists the values for lExpr.
lExpr Description True (.T.)
The object is visible. (Default in the Form Designer)
False (.F.)
The object is hidden. (Default in program code)
Note: Even when the object is hidden, you can still access it in code. Tip: To hide an object at startup, set the Visible property to False (.F.) at design time. If you set the Visible property in code, you can hide an object and display it at run time in response to a particular event.
Remarks
Applies To: CheckBox | Column | ComboBox | CommandButton | CommandGroup | Container Object | Control Object | EditBox | Form | FormSet | Grid | Image | Label | Line | ListBox | OLE Bound Control | OLE Container Control | OptionButton | OptionGroup | PageFrame | Project Object | _SCREEN | Separator | Shape | Spinner | TextBox | ToolBar
For Form objects, when Visible is set to False (.F.), the form is hidden and the most recently active form set, form, or other object becomes active. When Visible is set to True (.T.), the form becomes visible; however, the form does not become active. To make a form visible and active in the same step, use the Show method. For more information, see Show Method.
Note: |
---|
A form in a FormSet object does not display when its Visible property is set to False (.F.) even if the form set's Visible property is set to True (.T.). However, all forms in the form set are hidden if the form set's Visible property is set to False (.F.). |
Setting a form's Visible property to True (.T.) does not affect the form's Order property setting.
For Separator objects, the Visible property determines whether a space appears as the separator when its Style property is set to 0 (Normal - do not display a line). For example, when the separator's Visible property is set to True (.T.), and its Style property is set to 0, a space appears instead of the separator. When the separator's Visible property is set to False (.F.), no space appears, regardless of the setting of its Style property.
In versions prior to Visual FoxPro 5.0, setting the Visible property for the _SCREEN system variable has no effect.
Example
The following example displays a form with a line control and three command buttons based on three separate custom CommandButton classes. Pressing the "Slope Up" or "Slope Down" buttons change the slope of the line and pressing the Quit button ends the program. The Visible property is used to hide and display controls at appropriate times.
The following lines of code create a form and disable the form's Close button so the custom Quit button can be used to exit the program.
В | Copy Code |
---|---|
frmMyForm = CREATEOBJECT('Form') frmMyForm.Closable = .F. |
The following lines of code use the AddObject method to add a Line control and three custom command buttons to the form.
В | Copy Code |
---|---|
frmMyForm.AddObject('shpLine','Line') frmMyForm.AddObject('cmdCmndBtn1','cmdMyCmndBtn1') frmMyForm.AddObject('cmdCmndBtn2','cmdMyCmndBtn2') frmMyForm.AddObject('cmdCmndBtn3','cmdMyCmndBtn3') |
The Visible property is set to True (.T.) for the line control and the command buttons to display them on the form. The Top and Left properties specify the distance between the line control and the form.
В | Copy Code |
---|---|
frmMyForm.shpLine.Visible = .T. frmMyForm.cmdCmndBtn1.Visible =.T. frmMyForm.cmdCmndBtn2.Visible =.T. frmMyForm.cmdCmndBtn3.Visible =.T. frmMyForm.shpLine.Top = 20 frmMyForm.shpLine.Left = 125 |
The Show method displays the form and the READ EVENTS command begins event processing.
В | Copy Code |
---|---|
frmMyForm.SHOW READ EVENTS |
The DEFINE CLASS command defines three custom CommandButton classes and contains settings for the appropriate properties. In the Click event, the Visible property hides the line control so that its slope direction can be changed and displays the line control after its slant direction is changed. The CLEAR EVENTS command in the Click event of the third command button stops event processing and closes the form.
В | Copy Code |
---|---|
DEFINE CLASS cmdMyCmndBtn1 AS COMMANDBUTTON Caption = 'Slope \<Up' Left = 50 Top = 100 Height = 25 PROCEDURE Click ThisForm.shpLine.Visible = .F. ThisForm.shpLine.LineSlant ='/' ThisForm.shpLine.Visible = .T. ENDDEFINE DEFINE CLASS cmdMyCmndBtn2 AS CommandButton Caption = 'Slope \<Down' Left = 200 Top = 100 Height = 25 PROCEDURE Click ThisForm.shpLine.Visible = .F. ThisForm.shpLine.LineSlant ='\' ThisForm.shpLine.Visible = .T. ENDDEFINE DEFINE CLASS cmdMyCmndBtn3 AS CommandButton Caption = '\<Quit' Cancel = .T. Left = 125 Top = 150 Height = 25 PROCEDURE Click CLEAR EVENTS ENDDEFINE |