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
The following code demonstrates using the ParentForm property to access a method (in this example, GetMyParentFormData
) on the parent form:
[Visual Basic] Public Sub GetParentData() Dim x as String x = Me.ParentForm.GetMyParentFormData End Sub [C#] public void GetParentData(){ string x = ((Form1)this.ParentForm).GetMyParentFormData(); }
Dialog Boxes | ParentForm Property | Creating Dialog Boxes | Displaying Dialog Boxes for Win Forms | Closing Dialog Boxes and Retaining User Input | Retrieving the Result for Dialog Boxes | Retrieving Dialog Box Information Selectively Using Multiple Properties | Retrieving Dialog Box Information Collectively Using Objects