2

I try to build an application using WinForms and I need something like a JDialog frame to insert several TextBoxes in it (JTextField in Java) along with two buttons (OK and Cancel), but I haven't found yet any appropriate Windows form. Any suggestion?

Andrei
  • 217
  • 2
  • 12
  • possible duplicate of [Custom dialog box in C#?](http://stackoverflow.com/questions/6910122/custom-dialog-box-in-c) – sara Aug 10 '15 at 14:01

1 Answers1

1

There is no prompt dialog box in C#. You can create a custom prompt box to do this instead.

  public static class Prompt
    {
        public static int ShowDialog(string text, string caption)
        {
            Form prompt = new Form();
            prompt.Width = 500;
            prompt.Height = 100;
            prompt.Text = caption;
            Label textLabel = new Label() { Left = 50, Top=20, Text=text };
            NumericUpDown inputBox = new NumericUpDown () { Left = 50, Top=50, Width=400 };
            Button confirmation = new Button() { Text = "Ok", Left=350, Width=100, Top=70 };
            confirmation.Click += (sender, e) => { prompt.Close(); };
            prompt.Controls.Add(confirmation);
            prompt.Controls.Add(textLabel);
            prompt.Controls.Add(inputBox);
            prompt.ShowDialog();
            return (int)inputBox.Value;
        }
    }

Then call it using:

int promptValue = Prompt.ShowDialog("Test", "123");

I got this from here

Or use this:

using( MyDialog dialog = new MyDialog() )
{
    DialogResult result = dialog.ShowDialog();

    switch (result)
    {
    // put in how you want the various results to be handled
    // if ok, then something like var x = dialog.MyX;
    }

}
Community
  • 1
  • 1
Luca
  • 1,766
  • 3
  • 27
  • 38