NGWS SDK Documentation  

This is preliminary documentation and subject to change.
To comment on this topic, please send us email at ngwssdk@microsoft.com. Thanks!

Retrieving Dialog Box Information Collectively Using Objects

Most dialog boxes have properties that expose information provided within the dialog box. You might need to expose some or all of the information, depending on the amount of it the dialog box needs to convey to its parent form.

You can expose a group of related data from a dialog box by creating a class object that stores all of a dialog box's information. With this object created and defined, you can return all of the dialog box's data through a single property.

Before you can retrieve dialog box information, you need to create the class object that will disclose the dialog box information and expose it using a property in your dialog box class.

To provide dialog box data using an object

  1. Add a Class file to your project.
  2. Add properties to the class.
    Note   The properties allow you to set and retrieve values that are appropriate for the data returned.
  3. In the dialog box form, create the property that you will use to expose the data. Use the class you created as the data type for the property.
  4. In the property, add code to create an instance of the class you will use to provide the dialog box's data. Add code to set the class instance properties with values from your dialog box, and assign the object to the property.

    The following code demonstrates an example of how to define code for a dialog box's property that exposes geographical coordinate information:

    [Visual Basic]
    Public Property Get MapCoordinates() as MapCoordinates
    'Create an instance of your object. In this case, create a map coodinates 
    ' object that stores map latitude and longitude coordinates.
       Dim mc as MapCoordinates = new MapCoordinates
       mc.Latitude = Me.Latitude
       mc.Longitude = Me.Longitude
       MapCoordinates = mc
    End Sub
    [C#]
    public MapCoordinates MapCoordinates {
       get {
          // Create an instance of your object. In this case, create a map coodinates 
          // object that stores map latitude and longitude coordinates.
          MapCoordinates mc = new MapCoordinates();
          mc.Latitude = this.Latitude;
          mc.Longitude = this.Longitude;
          return mc;
       }
    }

You can retrieve the dialog box data through the parent form after you have provided a property and an object to expose through that property.

To retrieve dialog box data using an object

  1. In the method that displays the dialog box, add code to create an empty instance of the object you created to expose the dialog box data.
  2. Add code to assign the value of the property that contains the dialog box information to your empty instance of the dialog box data object. Add this code after the code that determines the result of the dialog box.
  3. Use the data provided by the object in your application.

    The following code demonstrates accessing the data from the MapCoordinates object:

    [Visual Basic]
    Public Sub DisplayMapDialogBox()
       'Create and display an instance of the dialog box
       Dim dlg as MapDialog = new MapDialog
       Dlg.ShowDialog
       'Determine the state of the DialogResult property for the form.
       If dlg.DialogResult = DialogResult.OK Then
          'Create an instance of the MapCoordinates object to store the 
          'dialog data.
          Dim mc as MapCoordinates
          mc = dlg.MapCoordinates
          'Display the values returned from the dialog box's return 
          'object.
          MessageBox.show mc.Latitude
          MessageBox.show mc.Longitude
       End If
    End Sub
    [C#]
    public void DisplayMapDialogBox() {
       // Create and display an instance of the dialog box
       MapDialog dlg = new MapDialog();
       dlg.ShowDialog();
       // Determine the state of the DialogResult property for the form.
       if (dlg.DialogResult == DialogResult.OK) {
          // Create an instance of the MapCoordinates object to store the 
          // dialog data.
          MapCoordinates mc = dlg.MapCoordinates;
          // Display the values returned from the dialog box's return 
          // object.
          MessageBox.Show (mc.Latitude);
          MessageBox.show (mc.Longitude);
       }
    }

See Also

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 the Result for Dialog Boxes | 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