ShapeContainer クラス
更新 : 2007 年 11 月
LineShape 、OvalShape、および RectangleShape の各コントロールに加えて、Shape から派生するその他のコントロールのコンテナを提供します。
名前空間 : Microsoft.VisualBasic.PowerPacks
アセンブリ : Microsoft.VisualBasic.PowerPacks.Vs (Microsoft.VisualBasic.PowerPacks.Vs.dll 内)
構文
'宣言
<BrowsableAttribute(False)> _
Public NotInheritable Class ShapeContainer _
Inherits UserControl
'使用
Dim instance As ShapeContainer
[BrowsableAttribute(false)]
public sealed class ShapeContainer : UserControl
[BrowsableAttribute(false)]
public ref class ShapeContainer sealed : public UserControl
public final class ShapeContainer extends UserControl
解説
LineShape コントロール、OvalShape コントロール、または RectangleShape コントロールは、ライン コントロールとシェイプ コントロールのキャンバスとして機能する ShapeContainer オブジェクトにのみ格納できます。
デザイン時に線または図形をフォームまたはコンテナに追加すると、ShapeContainer が自動的に作成されます (存在しない場合)。線または図形の Parent プロパティは、その ShapeContainer に設定されます。ShapeContainer の Parent プロパティは、線または図形が追加されたフォームまたはコンテナ コントロールに設定されます。
実行時に New メソッドを使用して線または図形を作成する場合は、コントロールの Parent プロパティを ShapeContainer に設定する必要があります。フォームまたはコンテナの ShapeContainer が既に存在する場合は、Parent プロパティをその ShapeContainer に設定する必要があります。ShapeContainer が存在しない場合は、New メソッドを使用して ShapeContainer を作成し、その Parent プロパティをフォームまたはコンテナに設定できます。
メモ : |
---|
各フォームまたはコンテナに対して複数の ShapeContainer を作成しないように注意してください。予期しない動作が発生する可能性があります。フォームまたはコンテナにデザイン時にライン コントロールまたはシェイプ コントロールを追加する前に、プログラムでこれらを作成するコードを記述していた場合は、デザイナによって作成された ShapeContainer を使用するようにコードを変更する必要があります。 |
例
既存の ShapeContainer の有無を確認し、New メソッドを使用して実行時に作成された OvalShape コントロールの Parent プロパティを設定する方法を次の例に示します。
Private Sub Form1_Load(ByVal sender As System.Object, _
ByVal e As System.EventArgs) 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);
}
継承階層
System.Object
System.MarshalByRefObject
System.ComponentModel.Component
System.Windows.Forms.Control
System.Windows.Forms.ScrollableControl
System.Windows.Forms.ContainerControl
System.Windows.Forms.UserControl
Microsoft.VisualBasic.PowerPacks.ShapeContainer
スレッド セーフ
この型のすべてのパブリック static (Visual Basic では Shared) メンバは、スレッド セーフです。インスタンス メンバの場合は、スレッド セーフであるとは限りません。
参照
参照
Microsoft.VisualBasic.PowerPacks 名前空間
その他の技術情報
ライン コントロールとシェイプ コントロールの概要 (Visual Studio)
方法 : LineShape コントロールを使用して線を描画する (Visual Studio)
方法 : OvalShape コントロールおよび RectangleShape コントロールを使用して図形を描画する (Visual Studio)