How to: Make Your Control Invisible at Run Time

 

There are times when you might want to create a user control that is invisible at run time. For example, a control that is an alarm clock might be invisible except when the alarm was sounding. This is easily accomplished by setting the Visible property. If the Visible property is true, your control will appear as normal. If false, your control will be hidden. Although code in your control may still run while invisible, you will not be able to interact with the control through the user interface. If you want to create an invisible control that still responds to user input (for example, mouse clicks), you should create a transparent control. For more information, see Giving Your Control a Transparent Background.

To make your control invisible at run time

  1. Set the Visible property to false.

    ' To set the Visible property from within your object's own code.  
    Me.Visible = False  
    ' To set the Visible property from another object.  
    myControl1.Visible = False  
    
    // To set the Visible property from within your object's own code.  
    this.Visible = false;  
    // To set the Visible property from another object.  
    myControl1.Visible = false;  
    

See Also

Visible
Developing Custom Windows Forms Controls with the .NET Framework
How to: Give Your Control a Transparent Background