Control.Visible 屬性
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
取得或設定值,這個值指出是否顯示控制項及其所有子控制項。
public:
property bool Visible { bool get(); void set(bool value); };
C#
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;
}
}
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;
}
}
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
如果您設定 Visible
為 true
:
- 如果使用者在其他控制項後方遮蔽控制項,則控制項可能無法顯示。
- 如果看不到父控制項,則不會顯示控制項。
產品 | 版本 |
---|---|
.NET Framework | 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1 |
Windows Desktop | 3.0, 3.1, 5, 6, 7, 8, 9, 10 |