共用方式為


Shape.Parent 屬性

取得或設定線條或圖形控制項的父容器。

命名空間:  Microsoft.VisualBasic.PowerPacks
組件:  Microsoft.VisualBasic.PowerPacks.Vs (在 Microsoft.VisualBasic.PowerPacks.Vs.dll 中)

語法

'宣告
<BrowsableAttribute(False)> _
Public Property Parent As ShapeContainer
[BrowsableAttribute(false)]
public ShapeContainer Parent { get; set; }
[BrowsableAttribute(false)]
public:
property ShapeContainer^ Parent {
    ShapeContainer^ get ();
    void set (ShapeContainer^ value);
}
[<BrowsableAttribute(false)>]
member Parent : ShapeContainer with get, set
function get Parent () : ShapeContainer 
function set Parent (value : ShapeContainer)

屬性值

類型:Microsoft.VisualBasic.PowerPacks.ShapeContainer
AShapeContainer代表父系或控制項的容器。

備註

A LineShapeOvalShape,或RectangleShape控制項可以只在包含ShapeContainer物件,做為 line 和 shape 控制項的畫布。

當您將加入線條或圖案的表單或容器在設計階段,ShapeContainer會自動建立,如果不存在。 Parent的線條或圖案的屬性設定為, ShapeContainer。 Parent屬性ShapeContainer設為線條或形狀已加入的表單或容器控制項。

當您建立線條或圖案在執行階段使用New方法中,您必須設定其Parent屬性設為ShapeContainer。 如果ShapeContainer已經存在的表單或容器,您應該設定Parent屬性的ShapeContainer。 如果沒有ShapeContainer存在,您可以建立ShapeContainer使用New方法,並設定其Parent的表單或容器的屬性。

注意事項注意事項

不會建立一個以上的ShapeContainer針對每個表單或容器,這樣可能會造成非預期的行為。如果您在撰寫程式碼以程式設計方式建立之後,將設計階段線條或圖形控制項加入表單或容器,您應該修改該程式碼以使用ShapeContainer設計工具建立。

範例

下列範例會檢查現有ShapeContainer,並設定Parent屬性OvalShape建立在執行階段使用的控制項New方法。

Dim NewOval As New OvalShape
Dim i As Integer 
Dim found As Boolean 
' Loop through the Controls collection. 
For i = 0 To Me.Controls.Count - 1
    ' If a ShapeContainer is found, make it the parent. 
    If TypeOf Controls.Item(i) Is ShapeContainer Then
        NewOval.Parent = Controls.Item(i)
        found = True 
        Exit For 
    End If 
Next 
' If no ShapeContainer is found, create one and set the parents. 
If found = False Then 
    Dim sc As New ShapeContainer
    sc.Parent = Me
    NewOval.Parent = sc
End If
NewOval.Size = New Size(200, 300)
OvalShape NewOval = new OvalShape();
int i;
bool found = false;
// Loop through the Controls collection. 
for (i = 0; i < this.Controls.Count; i++)
{
    // If a ShapeContainer is found, make it the parent. 
    if (this.Controls[i] is ShapeContainer)
    {
        NewOval.Parent = ((ShapeContainer)Controls[i]);
        found = true;
        break;
    }
}
// If no ShapeContainer is found, create one and set the parents. 
if (found == false)
{
    ShapeContainer sc = new ShapeContainer();
    sc.Parent = this;
    NewOval.Parent = sc;
}
NewOval.Size = new Size(200, 300);
found = true;

.NET Framework 安全性

請參閱

參考

Shape 類別

Microsoft.VisualBasic.PowerPacks 命名空間

其他資源

如何:使用 LineShape 控制項繪製線條 (Visual Studio)

如何:使用 OvalShape 和 RectangleShape 控制項繪製圖案 (Visual Studio)

Line 和 Shape 控制項簡介 (Visual Studio)