ShapeContainer 建構函式
初始化 ShapeContainer 類別的新執行個體。
命名空間: Microsoft.VisualBasic.PowerPacks
組件: Microsoft.VisualBasic.PowerPacks.Vs (在 Microsoft.VisualBasic.PowerPacks.Vs.dll 中)
語法
'宣告
Public Sub New
public ShapeContainer()
public:
ShapeContainer()
new : unit -> ShapeContainer
public function ShapeContainer()
備註
使用 New 方法時,在建立線條或形狀在執行階段,就必須將其 Parent 屬性為 ShapeContainer。 如果 ShapeContainer 為表單或容器的已經存在,您應該將 Parent 屬性為 ShapeContainer。 如果 ShapeContainer 不存在,您可以建立這個 ShapeContainer 是使用 New 方法並將其 Parent 屬性設定為表單或容器。
![]() |
---|
您不小心建立以上每個表單或容器的 ShapeContainer ;這樣做可能會造成未預期的行為。如果要加入設計階段線條和形狀控制項到表單或容器,在您撰寫程式碼以程式設計方式建立之後,您應該修改該程式碼使用設計工具建立的 ShapeContainer 。 |
範例
下列範例會檢查現有的 ShapeContainer 並且將 OvalShape 控制項的 Parent 屬性會在執行階段使用 New 方法。
Private Sub Form1_Load() Handles MyBase.Load
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)
End Sub
private void form1_Load(System.Object sender, System.EventArgs e)
{
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)this.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);
}
.NET Framework 安全性
- 完全信任立即呼叫者。這個成員無法供部分信任的程式碼使用。如需詳細資訊,請參閱從部分受信任程式碼使用程式庫。
請參閱
參考
Microsoft.VisualBasic.PowerPacks 命名空間
其他資源
Line 和 Shape 控制項簡介 (Visual Studio)