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 Retrieving Dialog Box Information Collectively Using Objects.
To expose dialog box information through properties
The following code demonstrates how to expose the value of a combo box through a property defined in a dialog box:
[Visual Basic] Public Property Get StateSelected () as String StateSelected = cmbState.Text End Sub [C#] public string StateSelected { get{ return comboBox1.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
[Visual Basic] Public Sub ShowMyDialog() 'Create and display an instance of the dialog box Dim Dlg as MyDialogBox = new MyDialogBox Dlg.ShowDialog 'Determine the state of the DialogResult property for the form. If Dlg.DialogResult = DialogResult.OK Then 'Display the state that was selected in the dialog box's combo 'box in a MessageBox. MessageBox.show Dlg.StateSelected End If End Sub [C#] private void ShowMyDialog() { // Create and display an instance of the dialog box DialogBox dlg = new DialogBox(); 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); } }
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 Collectively Using Objects | Retrieving Information from the Parent Form of a Dialog Box