我正在使用System.Windows.Forms
,但奇怪的是,我没有能力创建它们.
在没有javascript的情况下,如何获得javascript提示对话框?
MessageBox很好,但是用户无法输入.
我希望用户输入任何可能的文本输入.
我正在使用System.Windows.Forms
,但奇怪的是,我没有能力创建它们.
在没有javascript的情况下,如何获得javascript提示对话框?
MessageBox很好,但是用户无法输入.
我希望用户输入任何可能的文本输入.
您需要创建自己的提示对话框.您或许可以为此创建一个类.
public static class Prompt
{
public static string ShowDialog(string text, string caption)
{
Form prompt = new Form()
{
Width = 500,
Height = 150,
FormBorderStyle = FormBorderStyle.FixedDialog,
Text = caption,
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");
Update:
添加了默认按钮(enter key)和基于 comments 和another question的初始焦点.