首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >什么是JDialog for WinForms(WinForms)?

什么是JDialog for WinForms(WinForms)?
EN

Stack Overflow用户
提问于 2015-08-10 13:57:42
回答 1查看 719关注 0票数 2

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

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2015-08-10 14:01:48

C#中没有提示对话框。您可以创建一个自定义提示符框来代替。

代码语言:javascript
复制
  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;
        }
    }

然后使用以下方法调用它:

代码语言:javascript
复制
int promptValue = Prompt.ShowDialog("Test", "123");

我从here那里得到的

或者用这个:

代码语言:javascript
复制
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;
    }

}
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/31921549

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档