This topic has not yet been rated - Rate this topic

How to: Retrieve the Result for Dialog Boxes

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

  • Add code similar to the following to the method that displayed the dialog box.

    Typically, this code is placed after the code that creates and displays the dialog box:

    private:
       void DisplayDialog()
       {
          // Create and display an instance of the dialog box
          Form^ dlg = gcnew Form();
    
          // 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.
          }
       }
    
    NoteNote

    Be aware of the importance of calling the Dispose method on the form to properly dispose of the dialog box. Recall that this is not done automatically by clicking the Close box or calling the Close method.

Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback
Show:
© 2014 Microsoft. All rights reserved.