Export (0) Print
Expand All

How to: Retrieve Information from the Parent Form of a Dialog Box

Depending on what you need to do with your dialog box, you might want to have access to information provided by the dialog box's parent form. This information might be required for initialization of the dialog box or involve specific details about the application state of the parent form.

To access public data from a parent form

  1. Open the code for your form.

  2. At the appropriate location within your code, use the Form.ParentForm property of the dialog box to access the public members of the parent form. You should explicitly convert the reference returned by the ParentForm property to the appropriate type.

    The following code demonstrates using the ParentForm property to access a property (in this example, the Text property) on the parent form:

    public void GetParentText()
    {
       string x = ((Form1)this.ParentForm).Text;
    }
    
Show:
© 2014 Microsoft