C# WinForms(Windows窗体)的等效JDialog是什么?

C# WinForms(Windows窗体)的等效JDialog是什么?,c#,winforms,jdialog,C#,Winforms,Jdialog,我尝试使用WinForms构建一个应用程序,我需要一个类似于JDialog的框架来插入几个文本框(Java中的JTextField)以及两个按钮(OK和Cancel),但我还没有找到任何合适的Windows窗体。有什么建议吗?C#中没有提示对话框。您可以创建一个自定义提示框来执行此操作 public static class Prompt { public static int ShowDialog(string text, string caption)

我尝试使用WinForms构建一个应用程序,我需要一个类似于JDialog的框架来插入几个文本框(Java中的JTextField)以及两个按钮(OK和Cancel),但我还没有找到任何合适的Windows窗体。有什么建议吗?

C#中没有提示对话框。您可以创建一个自定义提示框来执行此操作

  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;
        }
    }
然后使用以下命令调用它:

int promptValue = Prompt.ShowDialog("Test", "123");
这是我从你那里得到的

或者使用以下命令:

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;
    }

}
可能重复的