Home > Codes > Retrieve and use input from a dialog box

Retrieve and use input from a dialog box

1. In the Code Editor, navigate to the event handler or the method for which you want to set the DialogResult property.

2. Add code to retrieve the DialogResult value.

The following code shows how user input is retrieved from an Open File dialog box.

public void DisplayValue()

{

DialogResult userResponse=

openFileDialog1.ShowDialog();

if (userResponse == DialogResult.OK)

{

filePath = openFileDialog1.FileName.ToString();

MessageBox.Show("You successfully opened: ‘" +

filePath + "’","Success",

MessageBoxButtons.OK,

MessageBoxIcon.Information,

MessageBoxDefaultButton.Button1);

}

else

{

MessageBox.Show("You canceled " +

"the open file operation.", "Warning",

MessageBoxButtons.OK,

MessageBoxIcon.Warning,

MessageBoxDefaultButton.Button1,

MessageBoxOptions.RightAlign);

}

Categories: Codes Tags: ,

Post Comments Below

  1. No comments yet.
  1. No trackbacks yet.