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
Note The properties allow you to set and retrieve values that are appropriate for the data returned.
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
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); } }
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