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!

Form.DialogResult

Gets or sets the dialog result for the form.

[Visual Basic]
Public Property DialogResult As DialogResult
[C#]
public DialogResult DialogResult {get; set;}
[C++]
public: __property DialogResult get_DialogResult();
public: __property void set_DialogResult(DialogResult);
[JScript]
public function get DialogResult() : DialogResult;
public function set DialogResult(DialogResult);

Property Value

A DialogResult that represents the result of the form when used as a dialog box.

Remarks

The dialog result of a form designates the value that is returned from the form when it is displayed as a modal dialog. Setting this property with a DialogResult sets the value of the dialog result for the form, closes the modal dialog, and returns control to the calling form. This property is typically set by the DialogResult property of a Button control on the form. When the user clicks on the Button control, the value assigned to DialogResult is assigned to the DialogResult property of the form.

You can use this property to determine how a dialog box is closed in order to properly process the actions perfomed in the dialog box.

Example [C#]

The following example displays a form as a dialog box and displays a MessageBox indicating whether the OK or Cancel button of the form was clicked by referencing the DialogResult property of the form.

[C#]

public void CreateMyForm()
{
   // Create a new instance of the form.
   Form form1 = new Form();
   // Create two buttons to use as the accept and cancel buttons.
   Button button1 = new Button ();
   Button button2 = new Button ();
  
   // Set the text of button1 to "OK".
   button1.Text = "OK";
   // Set the position of the button on the form.
   button1.Location = new Point (10, 10);
   // Set the text of button2 to "Cancel".
   button2.Text = "Cancel";
   // Set the position of the button based on the location of button1.
   button1.Location 
      = new Point (button1.Left, button1.Height + button1.Top + 10);
   // Make button1's dialog result OK.
   button1.DialogResult = DialogResult.OK;
   // Make button2's dialog result Cancel.
   button2.DialogResult = DialogResult.Cancel;
   // Set the caption bar text of the form.   
   form1.Text = "My Dialog Box";

   // Define the border style of the form to a dialog box.
   form1.BorderStyle = FormBorderStyle.FixedDialog
   // Set the accept button of the form to button1.
   form1.AcceptButton = button1;
   // Set the cancel button of the form to button2.
   form1.CancelButton = button2;
   // Set the start position of the form to the center of the screen.
   form1.StartPosition = FormStartPosition.CenterScreen;
   
   // Add button1 to the form.
   form1.Controls.Add(button1);
   // Add button2 to the form.
   form1.Controls.Add(button2);
   
   // Display the form as a modal dialog box.
   form1.ShowDialog();

   // Determine if the OK button was clicked on the dialog box.
   if (form1.DialogResult == DialogResult.OK)
      // Display a message box indicating that the OK button was clicked.
      MessageBox.show("The OK button on the form was clicked.");
   else
      // Display a message box indicating that the Cancel button was clicked.
      MessageBox.show("The Cancel button on the form was clicked.");
}

See Also

Form Class | Form Members | System.WinForms Namespace | DialogResult | DialogResult