Compartilhar via


Shape.GetContainerControl Method

Returns the next ContainerControl up in a line or shape control's chain of parent controls.

Namespace:  Microsoft.VisualBasic.PowerPacks
Assembly:  Microsoft.VisualBasic.PowerPacks.Vs (in Microsoft.VisualBasic.PowerPacks.Vs.dll)

Syntax

'Declaration
Public Function GetContainerControl As IContainerControl
public IContainerControl GetContainerControl()
public:
IContainerControl^ GetContainerControl()
member GetContainerControl : unit -> IContainerControl
public function GetContainerControl() : IContainerControl

Return Value

Type: System.Windows.Forms.IContainerControl
An IContainerControl that represents the parent of the control.

Remarks

For LineShape, OvalShape, and RectangleShape controls, the Parent property always returns a ShapeContainer object. The GetContainerControl method can be used to obtain the parent of the ShapeContainer object.

Examples

The following example sets the BackColor of the Panel control that contains an OvalShape control. This example requires that you have a Panel control named Panel1 and an OvalShape control named OvalShape1 on a form.

Private Sub OvalShape1_Click() Handles OvalShape1.Click
    ' Declare a Control. 
    Dim ctl As Control
    ' Find the container for the OvalShape.
    ctl = OvalShape1.GetContainerControl.ActiveControl.Parent
    ' Change the color of the container.
    ctl.BackColor = Color.Blue
End Sub
private void ovalShape1_Click(System.Object sender, System.EventArgs e)
{
    // Declare a Control.
    Control ctl;
    // Find the container for the OvalShape.
    ctl = ((Control)ovalShape1.GetContainerControl());
    // Change the color of the container.
    ctl.BackColor = Color.Blue;
}

.NET Framework Security

See Also

Reference

Shape Class

Microsoft.VisualBasic.PowerPacks Namespace

Other Resources

How to: Draw Lines with the LineShape Control (Visual Studio)

How to: Draw Shapes with the OvalShape and RectangleShape Controls (Visual Studio)

Introduction to the Line and Shape Controls (Visual Studio)