Control.Visible 屬性

定義

取得或設定值,這個值指出是否顯示控制項及其所有子控制項。

public:
 property bool Visible { bool get(); void set(bool value); };
public bool Visible { get; set; }
member this.Visible : bool with get, set
Public Property Visible As Boolean

屬性值

true 表示顯示控制項及其子控制項;否則為 false 。 預設值為 true。 取得值時, true 只有在控制項可見且父控制項存在時,才會傳回 。

範例

下列程式碼範例會使用衍生類別 VScrollBar ,並根據 HScrollBar 控制項中顯示的 PictureBox 大小 Image 來設定其 Visible 屬性值。 這個範例會要求 已在表單上建立 , PictureBox 而且 HScrollBar 已在 上 PictureBox 建立 和 VScrollBar 控制項。 當影像載入圖片方塊和 Resize 表單的 事件時,應該呼叫此程式碼。

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

備註

如果您設定 Visibletrue

  • 如果使用者在其他控制項後方遮蔽控制項,則控制項可能無法顯示。
  • 如果看不到父控制項,則不會顯示控制項。

適用於

另請參閱