Guest User

Untitled

a guest
Apr 23rd, 2012
26
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.91 KB | None | 0 0
  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");
Advertisement
Add Comment
Please, Sign In to add comment