Once a dialog box is closed, the form that displayed the dialog box can retrieve the result of that dialog box by referencing its DialogResult property or the return value of a call to the ShowDialog method. The form that displayed the dialog box then responds according to the value returned.
To retrieve the DialogResult value
Typically, this code is entered below the code that creates and displays the dialog box:
[Visual Basic] Public Sub DisplayDialog() 'Create and display an instance of the dialog box Dim dlg as MyDialogBox = new MyDialogBox 'Show the dialog and determine the state of the 'DialogResult property for the form. If dlg.ShowDialog = DialogResult.OK Then 'Do Something Here to Handle Data From Dialog Box End If End Sub [C#] private void DisplayDialog() { // Create and display an instance of the dialog box MyDialogBox dlg = new MyDialogBox(); // Show the dialog and determine the state of the // DialogResult property for the form. if (dlg.ShowDialog() == DialogResult.OK ) { // Do Something Here to Handle Data From Dialog Box } }
Dialog Boxes | How to Handle User Input to Dialog Boxes | Creating Dialog Boxes | Displaying Dialog Boxes for Win Forms | Closing Dialog Boxes and Retaining User Input | Retrieving Dialog Box Information Selectively Using Multiple Properties | Retrieving Dialog Box Information Collectively Using Objects | Retrieving Information from the Parent Form of a Dialog Box