Gets or sets the parent container of the control.
Assembly: System.Windows.Forms (in System.Windows.Forms.dll)
'Declaration <BrowsableAttribute(False)> _ Public Property Parent As Control 'Usage Dim instance As Control Dim value As Control value = instance.Parent instance.Parent = value
Setting the property value to Nothing removes the control from the Control.ControlCollection of its current parent control.
The following code example uses the property and the FindForm method to set properties on the parent control of a button and its form.
' This example uses the Parent property and the Find method of Control to set ' properties on the parent control of a Button and its Form. The example assumes ' that a Button control named button1 is located within a GroupBox control. The ' example also assumes that the Click event of the Button control is connected to ' the event handler method defined in the example. Private Sub button1_Click(sender As Object, e As System.EventArgs) Handles button1.Click ' Get the control the Button control is located in. In this case a GroupBox. Dim control As Control = button1.Parent ' Set the text and backcolor of the parent control. control.Text = "My Groupbox" control.BackColor = Color.Blue ' Get the form that the Button control is contained within. Dim myForm As Form = button1.FindForm() ' Set the text and color of the form containing the Button. myForm.Text = "The Form of My Control" myForm.BackColor = Color.Red End Sub
Windows 7, Windows Vista, Windows XP SP2, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP Starter Edition, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003, Windows Server 2000 SP4, Windows Millennium Edition, Windows 98, Windows CE, Windows Mobile for Smartphone, Windows Mobile for Pocket PC
The .NET Framework and .NET Compact Framework do not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.