Shape.Parent 属性
更新:2007 年 11 月
获取或设置 Line 或 Shape 控件的父容器。
命名空间: Microsoft.VisualBasic.PowerPacks
程序集: Microsoft.VisualBasic.PowerPacks.Vs(在 Microsoft.VisualBasic.PowerPacks.Vs.dll 中)
语法
声明
<BrowsableAttribute(False)> _
Public Property Parent As ShapeContainer
用法
Dim instance As Shape
Dim value As ShapeContainer
value = instance.Parent
instance.Parent = value
[BrowsableAttribute(false)]
public ShapeContainer Parent { get; set; }
[BrowsableAttribute(false)]
public:
property ShapeContainer^ Parent {
ShapeContainer^ get ();
void set (ShapeContainer^ value);
}
public function get Parent () : ShapeContainer
public function set Parent (value : ShapeContainer)
属性值
类型:Microsoft.VisualBasic.PowerPacks.ShapeContainer
一个表示控件的父级或容器的 ShapeContainer。
备注
LineShape、OvalShape 或 RectangleShape 控件只能包含在 ShapeContainer 对象中,该对象充当 Line 和 Shape 控件的画布。
在设计时向窗体或容器添加 Line 或 Shape 时,会自动创建一个 ShapeContainer,但前提是它尚不存在。 Line 或 Shape 的 Parent 属性设置为该 ShapeContainer。 ShapeContainer 的 Parent 属性设置为 Line 或 Shape 所添加到的窗体或容器控件。
在运行时使用 New 方法创建 Line 或 Shape 时,必须将其 Parent 属性设置为 ShapeContainer。 如果窗体或容器已经存在 ShapeContainer,则应该将 Parent 属性设置为该 ShapeContainer。 如果不存在 ShapeContainer,则可以使用 New 方法创建一个 ShapeContainer,并将它的 Parent 属性设置为窗体或容器。
说明: |
---|
不要为一个窗体或容器创建一个以上的 ShapeContainer;否则可能会引入意外的行为。 在通过编写代码来以编程方式创建窗体或容器后,如果向其中添加设计时线条或形状控件,则应该修改该代码,让线条或形状控件使用由设计器创建的 ShapeContainer。 |
示例
下面的示例检查是否存在 ShapeContainer,并为在运行时使用 New 方法创建的 OvalShape 控件设置 Parent 属性。
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;
权限
- 对直接调用方的完全信任。此成员不能由部分信任的代码使用。有关更多信息,请参见通过部分受信任的代码使用库。
另请参见
参考
Microsoft.VisualBasic.PowerPacks 命名空间
其他资源
如何:使用 LineShape 控件绘制直线 (Visual Studio)