Export (0) Print
Expand All
This topic has not yet been rated - Rate this topic

How to: Retrieve Dialog Box Information Selectively Using Multiple Properties

A common way to process the information returned from a dialog box is to provide a set of properties that return individual elements of dialog box data. This way, you can selectively extract data from the dialog box.

If you have dialog box data that is related, consider exposing some information through objects. For details, see Walkthrough: Retrieving Dialog Box Information Collectively Using Objects.

To expose dialog box information through properties

  1. In the class containing the code for your dialog box, create as many properties as needed to expose the necessary information for your dialog box. Provide a return value that is appropriate for the type of data you are providing.

  2. Add code to the Get portion of the property definition. If you want to prevent a user from changing the dialog box information outside of the dialog box, remove the Set portion of the property definition.

    The following code demonstrates how to expose the value of a combo box (cmbState) through a property defined in a dialog box:

    public string StateSelected 
    {
       get
       {
          return cmbState.Text; 
       }
    }
    

Once you have exposed properties for all of the data you want to provide, you can retrieve the data from the application that uses the dialog box.

To retrieve data from the properties of a dialog box

  • In the form that is displaying the dialog box, open the event handler or method that you used to display the dialog box and determine its DialogResult. Add code to collect the properties of the dialog box's form as demonstrated in the following example:

    private void ShowMyDialog() 
    {
       // Create and display an instance of the dialog box.
       Form1 dlg = new Form1();
       dlg.ShowDialog();
       // Determine the state of the DialogResult property for the form.
       if (dlg.DialogResult == DialogResult.OK) 
       {
          // Display the state that was selected in the dialog box's combo 
          // box in a MessageBox.
          MessageBox.Show (dlg.StateSelected);
       }
    }
    
Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback
Show:
© 2014 Microsoft. All rights reserved.