ShapeContainer (Constructor)
Inicializa una nueva instancia de la clase ShapeContainer.
Espacio de nombres: Microsoft.VisualBasic.PowerPacks
Ensamblado: Microsoft.VisualBasic.PowerPacks.Vs (en Microsoft.VisualBasic.PowerPacks.Vs.dll)
Sintaxis
'Declaración
Public Sub New
public ShapeContainer()
public:
ShapeContainer()
new : unit -> ShapeContainer
public function ShapeContainer()
Comentarios
Cuando se crea una línea o una forma en tiempo de ejecución mediante el método de New , la propiedad de Parent establecido en ShapeContainer. Si ShapeContainer ya existe en el formulario o contenedor, debe establecer la propiedad de Parent a ese ShapeContainer. Si no existe ningún ShapeContainer , puede crear ShapeContainer utilizando el método de New y establecer su propiedad de Parent al formulario o el contenedor.
Nota
Tenga cuidado de no crear más de un ShapeContainer para cada formulario o contenedor; ello puede presentar un comportamiento inesperado.Si agrega una línea de tiempo de diseño o un control de forma a un formulario o contenedor después de escribir el código para crear uno mediante programación, debe modificar el código para utilizar ShapeContainer creado por el diseñador.
Ejemplos
Comprueba el siguiente ejemplo ShapeContainer existente y conjuntos que la propiedad de Parent de un control de OvalShape creado en tiempo de ejecución mediante el método de 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);
}
Seguridad de .NET Framework
- Plena confianza para el llamador inmediato. Un código de confianza parcial no puede utilizar este miembro. Para obtener más información, vea Utilizar bibliotecas de código que no es de plena confianza.
Vea también
Referencia
Microsoft.VisualBasic.PowerPacks (Espacio de nombres)
Otros recursos
Introducción a los controles de líneas y formas (Visual Studio)
Cómo: Dibujar líneas con el control LineShape (Visual Studio)
Cómo: Dibujar formas con los controles OvalShape y RectangleShape (Visual Studio)