Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Apr 23rd, 2012  |  syntax: None  |  size: 0.91 KB  |  hits: 14  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. Easiest way to create a custom dialog box which returns a value?
  2. public static class Prompt
  3.     {
  4.         public static int ShowDialog(string text, string caption)
  5.         {
  6.             Form prompt = new Form();
  7.             prompt.Width = 500;
  8.             prompt.Height = 100;
  9.             prompt.Text = caption;
  10.             Label textLabel = new Label() { Left = 50, Top=20, Text=text };
  11.             NumericUpDown inputBox = new NumericUpDown () { Left = 50, Top=50, Width=400 };
  12.             Button confirmation = new Button() { Text = "Ok", Left=350, Width=100, Top=70 };
  13.             confirmation.Click += (sender, e) => { prompt.Close(); };
  14.             prompt.Controls.Add(confirmation);
  15.             prompt.Controls.Add(textLabel);
  16.             prompt.Controls.Add(inputBox);
  17.             prompt.ShowDialog();
  18.             return (int)inputBox.Value;
  19.         }
  20.     }
  21.        
  22. int promptValue = Prompt.ShowDialog("Test", "123");