Alex Rivera | Logout

Messagebox with input field

Asked 2012-05-29T10:57:40.637
84

Is it possible to show (pop-up) a message box with an input field in it, possibly a text box? Is somewhere in the language or the framework?

Edit
Report

1 Answer

67

You can do it by making form and displaying it using ShowDialogBox....

Form.ShowDialog Method - Shows the form as a modal dialog box.

Example:

public void ShowMyDialogBox()
{
   Form2 testDialog = new Form2();

   // Show testDialog as a modal dialog and determine if DialogResult = OK.
   if (testDialog.ShowDialog(this) == DialogResult.OK)
   {
      // Read the contents of testDialog's TextBox.
      this.txtResult.Text = testDialog.TextBox1.Text;
   }
   else
   {
      this.txtResult.Text = "Cancelled";
   }
   testDialog.Dispose();
}
answered 2012-05-29T10:59:17.660

Your Answer