Parent Property

See Also2YA44CK              Example2U9IBW4>Low

Applies To

Check box9P3BU5, combo box1YZXFF6, command buttonXJSPC0, directory list boxO9U5A0, drive list box5WJO0PW, file list box1M6S8UX, frame1KX6ZP8, grid2VGT0PT, horizontal scroll bar1JSJOS7, image9A4FCA, label3MNIZ8D, lineTW530P, list boxG11UCK, menuBKDT1F, OLE control2HQDVVU, option buttonJYBO08, picture box31MYIWX, shape9JZFLA, text boxYPYZDG, timer3MVR08J, vertical scroll bar1JSJOS7.

Description

Specifies the form on which a control is located; not available at design time and read-only at run time.

Usage

[form.]control.Parent

Remarks

Use the Parent property to access the properties, methods, or controls of a control's parent formfor example, MyButton.Parent.MousePointer = 4.

The Parent property is useful in an application in which you pass controls as arguments.  For example, you might pass a control variable to a general procedure in a module, and use the Parent property to access its parent form.

 

Note   There is no relationship between the Parent property and the MDIChildBJG7BM property.  There is, however, a parent-child relationship between an MDI form and any forms in your project that have the MDIChild property set to True.

 

Data Type

Form14TJ2LN


See Also

Help:

ActiveControl PropertyJCXG6P

ActiveForm PropertyGCUI9X

 

Programmer's Guide:

Chapter 8, "Objects and Instances"


Parent Property Example

The example passes a control from a form that doesn't have the focus to a procedure in a module, and then prints the state of the control on the parent form.  To try this example, create three forms: Form1, containing a command button; and Form2 and Form3, each containing a check box. You must also create a new module (choose the New Module command from the File menu).  Paste the code into the Declarations sections of the respective forms or module and then press F5 to run the program.

' Enter into Form1:

Sub Form_Load ()

   Form2.Show                   ' Display all forms.

   Form3.Show

   Form2.AutoRedraw = True

   Form3.AutoRedraw = True

End Sub

 

Sub Command1_Click ()

   CheckCheck Form2.Check1      ' Call procedure in other module.

   CheckCheck Form3.Check1      ' And send control as argument.

End Sub

 

' Enter into Module1:

Sub CheckCheck (Source As Control)

   If Source.Value Then

      Source.Parent.Cls                       ' Clear parent form.

      Source.Parent.Print "CheckBox is ON"    ' Print on parent form.

   Else

      Source.Parent.Cls                       ' Clear parent form.

      Source.Parent.Print "CheckBox is OFF"   ' Print on parent form.

   End If

End Sub