Control.Visible 属性

获取或设置一个值,该值指示是否显示该控件。

**命名空间:**System.Windows.Forms
**程序集:**System.Windows.Forms(在 system.windows.forms.dll 中)

语法

声明
<LocalizableAttribute(True)> _
Public Property Visible As Boolean
用法
Dim instance As Control
Dim value As Boolean

value = instance.Visible

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

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

public function set Visible (value : boolean)

属性值

如果显示该控件,则为 true,否则为 false。默认为 true

示例

下面的代码示例使用派生类 VScrollBarHScrollBar,并基于 PictureBox 控件中显示的 Image 的大小,设置它们的 Visible 属性值。此示例要求已经在窗体上创建了 PictureBox,并且已经在 PictureBox 上创建了 HScrollBarVScrollBar 控件。当图像加载到图片框时,应由窗体的 Resize 事件调用此代码。

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
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;
    }
 }
 
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;
      }
   }
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
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;
    }
 }
 

平台

Windows 98、Windows 2000 SP4、Windows CE、Windows Millennium Edition、Windows Mobile for Pocket PC、Windows Mobile for Smartphone、Windows Server 2003、Windows XP Media Center Edition、Windows XP Professional x64 Edition、Windows XP SP2、Windows XP Starter Edition

.NET Framework 并不是对每个平台的所有版本都提供支持。有关受支持版本的列表,请参见系统要求

版本信息

.NET Framework

受以下版本支持:2.0、1.1、1.0

.NET Compact Framework

受以下版本支持:2.0、1.0

请参见

参考

Control 类
Control 成员
System.Windows.Forms 命名空间
Control.Enabled 属性
Control.CanFocus 属性
Hide
SetVisibleCore