Home

Controls Properties: Control's Visibility

 

Introduction

A control is referred to as visible if it can be visually located on the screen. A user can use a control only if he or she can see it. As a programmer, you have the role of deciding whether a control must be seen or not and when. The visibility of an object is controlled by the its Visible property. This is a Boolean property.

At design time, when you add a control to a parent, it is visible by default. This is because its Visible property is set to True in the Properties window. In the same way, if you programmatically create a control, by default, it is made visible once you add it to its parent's Controls property.

If you don't want a control to primarily appear when the form comes up, you can either set its Visible property to False or set its parent’s visible property to False. Equivalently, at run time, to hide a control, assign a False value to either its Visible property or its parent’s Visible property. Keep in mind that when a parent gets hidden, it also hides its children. On the other hand, a parent can be made visible but hide one or some of its children.

To programmatically check whether a control is visible at one time, apply a conditional statement (if or while) to its Visible property and check whether its value is true or false.

Control's Visibility

In the previous section, we saw that you could call the Visible property to hide a visible control or to display a hidden control. Besides the Visible property, you can also display a control using the Show() method. Its syntax is:

Public Sub Show()

When you use this method, if the control is visible, nothing would happen. If it were hidden, then it would be revealed. The Show() method internally sets the Visible property to true. We also saw that, to hide a control, you could set its Visible property to False. In the same way, to hide a control, you call can the Control.Hide() method. Its syntax is:

Public Sub Hide()

Keep in mind that hiding a control does not destroy it.

 

 

Home Copyright © 2008 FunctionX, Inc. Home