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!

Closing Dialog Boxes and Retaining User Input

The way a dialog box is closed, or its “result,” can be set at either design time or run time: At design time, you can set the DialogResult property for all of the Button controls on a dialog box. Setting the DialogResult property at run time allows you to dynamically handle user responses.

You can set the dialog result for user-performed actions other than clicking a Button control. If your dialog box does not contain buttons to close the dialog box, you can manually set the result of the dialog box at run time.

To set the DialogResult property for a control or form at run time

  1. In your coed editor, open the event-handling method or method that you want to set the DialogResult property for.
  2. Type code similar to the following:
    [Visual Basic]
    Public Sub InformationProcessed()
       'This code will set the DialogResult for a form.
       Me.DialogResult = DialogResult.Yes
       'OR
       'This code will set the DialogResult for a button.
       Button1.DialogResult = DialogResult.No
    End Sub
    [C#]
    private void InformationProcessed() {
       // This code will set the DialogResult for a form.
       DialogResult = DialogResult.Yes;
       // OR
       // This code will set the DialogResult for a button.
       Button1.DialogResult = DialogResult.No;
    }
    

Although setting the DialogResult property will cause your dialog box to close automatically, you can still handle the control's Click event and the dialog box will close once the event-handling method’s code is finished. While handling the Click event, you may want to halt the closure of the dialog box.

To stop the DialogResult property from closing the dialog box

See Also

Dialog Boxes | How to Handle User Input to Dialog Boxes | Creating Dialog Boxes | 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