Control (Propiedades)


Control.Visible (Propiedad)
Obtiene o establece un valor que indica si se muestran el control y todos sus controles primarios.

Espacio de nombres: System.Windows.Forms
Ensamblado: System.Windows.Forms (en system.windows.forms.dll)

Sintaxis

Visual Basic (Declaración)
<LocalizableAttribute(True)> _
Public Property Visible As Boolean
Visual Basic (Uso)
Dim instance As Control
Dim value As Boolean

value = instance.Visible

instance.Visible = value
C#
[LocalizableAttribute(true)] 
public bool Visible { get; set; }
C++
[LocalizableAttribute(true)] 
public:
property bool Visible {
    bool get ();
    void set (bool value);
}
J#
/** @property */
public boolean get_Visible ()

/** @property */
public void set_Visible (boolean value)
JScript
public function get Visible () : boolean

public function set Visible (value : boolean)
XAML
No aplicable.

Valor de propiedad

Es true si se muestran el control y todos sus controles primarios; en caso contrario, es false. El valor predeterminado es true.
Ejemplo

En el siguiente ejemplo de código se utilizan las clases derivadas VScrollBar y HScrollBar, y se establecen los valores de la propiedad Visible en función del tamaño de una Image que se muestra en un control PictureBox. En este ejemplo se requiere que se haya creado PictureBox en un formulario, y que se han creado controles HScrollBar y VScrollBar en PictureBox. Debe llamarse a este código cuando la imagen se cargue en el cuadro de imagen, mediante el evento Resize del formulario.

Visual Basic
Public Sub DisplayScrollBars()
    ' Display or hide the scroll bars based upon  
    ' whether the image is larger than the PictureBox.
    If pictureBox1.Width > pictureBox1.Image.Width Then
        hScrollBar1.Visible = False
    Else
        hScrollBar1.Visible = True
    End If
    
    If pictureBox1.Height > pictureBox1.Image.Height Then
        vScrollBar1.Visible = False
    Else
        vScrollBar1.Visible = True
    End If
End Sub 'DisplayScrollBars
C#
public void DisplayScrollBars()
 {
    // Display or hide the scroll bars based upon  
    // whether the image is larger than the PictureBox.
    if (pictureBox1.Width > pictureBox1.Image.Width)
    {
       hScrollBar1.Visible = false;
    }
    else
    {
       hScrollBar1.Visible = true;
    }
    
    if (pictureBox1.Height > pictureBox1.Image.Height)
    {
       vScrollBar1.Visible = false;
    }
    else
    {
       vScrollBar1.Visible = true;
    }
 }
 
C++
public:
   void DisplayScrollBars()
   {
      // Display or hide the scroll bars based upon  
      // whether the image is larger than the PictureBox.
      if ( pictureBox1->Width > pictureBox1->Image->Width )
      {
         hScrollBar1->Visible = false;
      }
      else
      {
         hScrollBar1->Visible = true;
      }

      if ( pictureBox1->Height > pictureBox1->Image->Height )
      {
         vScrollBar1->Visible = false;
      }
      else
      {
         vScrollBar1->Visible = true;
      }
   }
J#
public void DisplayScrollBars()
{
    // Display or hide the scroll bars based upon  
    // whether the image is larger than the PictureBox.
    if (pictureBox1.get_Width() > pictureBox1.get_Image().get_Width()) {
        hScrollBar1.set_Visible(false);
    }
    else {
        hScrollBar1.set_Visible(true);
    }

    if (pictureBox1.get_Height() > pictureBox1.get_Image().get_Height()) {
        vScrollBar1.set_Visible(false);
    }
    else {
        vScrollBar1.set_Visible(true);
    }
} //DisplayScrollBars
JScript
public function DisplayScrollBars()
 {
    // Display or hide the scroll bars based upon  
    // whether the image is larger than the PictureBox.
    if (pictureBox1.Width > pictureBox1.Image.Width)
    {
       hScrollBar1.Visible = false;
    }
    else
    {
       hScrollBar1.Visible = true;
    }
    
    if (pictureBox1.Height > pictureBox1.Image.Height)
    {
       vScrollBar1.Visible = false;
    }
    else
    {
       vScrollBar1.Visible = true;
    }
 }
 
Plataformas

Windows 98, Windows 2000 Service Pack 4, Windows CE, Windows Millennium, Windows Mobile para Pocket PC, Windows Mobile para Smartphone, Windows Server 2003, Windows XP Media Center, Windows XP Professional x64, Windows XP SP2, Windows XP Starter

Microsoft .NET Framework 3.0 es compatible con Windows Vista, Microsoft Windows XP SP2 y Windows Server 2003 SP1.

Información de versión

.NET Framework

Compatible con: 3.0, 2.0, 1.1, 1.0

.NET Compact Framework

Compatible con: 2.0, 1.0
Vea también

Page view tracker