Older Version Newer Version

Alyce Alyce May 18, 2012

**Show and Hide Controls**
//[[user:Alyce]]//
[[toc|flat]]
----
=Create Visible Controls=
Windows and controls are visible by default. 

=Create Hidden Controls=
We can create a control that is initially hidden if we use the STYLEBITS statement with the style _WS_VISIBLE in the "remove bits" spot. It looks like this:

[[code format="lb"]]
stylebits #1.btn, 0, _WS_VISIBLE, 0, 0
[[code]]

_WS_VISIBLE is the constant value for "window style visible". In the code above it is in the spot for stylebits removed from the default Liberty BASIC style, so the control will not be visible when the window is opened.

=Command Strings=
In Liberty BASIC we send commands to controls as a string of text. Some controls can accept new captions or text, so a string of text sent to these controls is displayed on the control. Sending the string "hide" to a button will cause the button caption to display "hide". It will not cause the button to be hidden. Controls that accept text strings need the character **!** (exclamation point) to be prepended to the text string.

[[code format="lb"]]
'Change button caption to HIDE
#1.btn "HIDE"
'Hide the button
#1.btn "!HIDE"
[[code]]

Some examples of controls that require command strings to begin with **!** are buttons, textboxes,  and statictext controls. Some examples of controls that do not require the prepended exclamation point in command strings are listboxes, comboboxes and graphicboxes.

=The SHOW statement=
Use the "show" statement to cause a control to be visible. If the control is already visible, it will remain visible. If the control is hidden, it will be displayed.
[[code format="lb"]]
    #1.button "!show"  'display control
    #1.listbox "show"  'display control
[[code]]

=The HIDE statement=
Use the "hide" statement to hide a control. If the control is not visible, it will remain hidden. If it is visible, it will be hidden.
[[code format="lb"]]
    #1.button "!hide"  'hide control
    #1.listbox "hide"  'hide control
[[code]]

=Refresh?=
The **refresh** statement is used when controls are moved with the **locate** statement. Controls that are moved or resized with **locate** do not display in their new locations or sizes until a **refresh** statement is sent to their parent window. The "refresh" statement is **not** used when controls are shown or hidden. Controls are hidden or shown as soon as they receive the "hide" or "show" command.

=Demo=
[[code format="lb"]]
nomainwin
for i = 1 to 10
    list$(i)="List Item ";str$(i)
next

stylebits #1.btn, 0, _WS_VISIBLE, 0, 0
stylebits #1.list, 0, _WS_VISIBLE, 0, 0
button #1.btn, "Button",[nothing],UL,10,60
listbox #1.list, list$(),[nothing],10,100,100,120
button #1.flip, "Show",[hideShow],UL,10,10
open "Hide and Show Controls" for window as #1

wait
[quit] close #1:end

[hideShow]
if Shown then
    #1.btn "!hide"  'hide control
    #1.list "hide"  'hide control
    #1.flip "Show"  'change caption
else
    #1.btn "!show"  'display control
    #1.list "show"  'display control
    #1.flip "Hide"  'change caption
end if
Shown=not(Shown)
wait

[nothing] wait

[[code]]
----
[[toc|flat]]