本文介绍了提示对话框中的Windows窗体的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我使用 System.Windows.Forms的
,但奇怪的是没有建立它们的能力。
I am using System.Windows.Forms
but strangely enough don't have the ability to create them.
我怎么能得到这样一个JavaScript提示对话框,没有JavaScript的?
How can I get something like a javascript prompt dialog, without javascript?
的MessageBox是好的,但也没有办法为用户输入的输入。
MessageBox is nice, but there is no way for the user to enter an input.
推荐答案
您需要创建自己的提示对话框。也许你可以为此创建一个类。
You need to create your own Prompt dialog. You could perhaps create a class for this.
public static class Prompt
{
public static string ShowDialog(string text, string caption)
{
Form prompt = new Form();
prompt.Width = 500;
prompt.Height = 150;
prompt.FormBorderStyle = FormBorderStyle.FixedDialog;
prompt.Text = caption;
prompt.StartPosition = FormStartPosition.CenterScreen;
Label textLabel = new Label() { Left = 50, Top=20, Text=text };
TextBox textBox = new TextBox() { Left = 50, Top=50, Width=400 };
Button confirmation = new Button() { Text = "Ok", Left=350, Width=100, Top=70, DialogResult = DialogResult.OK };
confirmation.Click += (sender, e) => { prompt.Close(); };
prompt.Controls.Add(textBox);
prompt.Controls.Add(confirmation);
prompt.Controls.Add(textLabel);
prompt.AcceptButton = confirmation;
return prompt.ShowDialog() == DialogResult.OK ? textBox.Text : "";
}
}
和调用它:
string promptValue = Prompt.ShowDialog("Test", "123");
更新
添加默认按钮(回车键),并初步重点的基础上的意见和another问题。
Added default button (enter key) and initial focus based on comments and another question.
这篇关于提示对话框中的Windows窗体的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!