Shape.FindForm Method ()

 

Retrieves the form that a line or shape control is on.

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

public Form FindForm()

Return Value

Type: System.Windows.Forms.Form

The Form that the control is on.

The control's Parent property value will not be the same as the Form returned by the FindForm method. The parent of a line or shape control is always a ShapeContainer, and the ShapeContainer could be contained in a container control. Consider an example in which a LineShape control is contained in a GroupBox control and the GroupBox is on a Form. In this example, the control's Parent is a ShapeContainer, the ShapeContainer object's Parent is a GroupBox, and the GroupBox control's Parent is the Form.

The following example demonstrates how to use the FindForm method to determine which form contains a LineShape control.

private void GetTheForm()
{
    Form myForm = lineShape1.FindForm();
    // Set the text and color of the form that contains the LineShape.
    myForm.Text = "This form contains a line";
    myForm.BackColor = Color.Red;
}
Return to top
Show: