C# 带有输入字段的消息框
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/10797774/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Messagebox with input field
提问by Sunscreen
Is it possible to show (pop-up) a message box with an input field in it, possibly a text box? Is somewhere in the language or the framework?
是否可以显示(弹出)一个带有输入字段的消息框,可能是一个文本框?在语言或框架中的某个地方?
采纳答案by animaonline
You can reference Microsoft.VisualBasic.dll.
可以参考Microsoft.VisualBasic.dll。
Then using the code below.
然后使用下面的代码。
Microsoft.VisualBasic.Interaction.InputBox("Question?","Title","Default Text");
Alternatively, by adding a usingdirective allowing for a shorter syntax in your code (which I'd personally prefer).
或者,通过添加using允许在代码中使用更短语法的指令(我个人更喜欢)。
using Microsoft.VisualBasic;
...
Interaction.InputBox("Question?","Title","Default Text");
Or you can do what Pranay Rana suggests, that's what I would've done too...
或者你可以按照 Pranay Rana 的建议去做,这也是我会做的......
回答by Pranay Rana
You can do it by making form and displaying it using ShowDialogBox....
您可以通过制作表单并使用 ShowDialogBox 显示它来做到这一点....
Form.ShowDialog Method- Shows the form as a modal dialog box.
Form.ShowDialog Method- 将表单显示为模式对话框。
Example:
例子:
public void ShowMyDialogBox()
{
Form2 testDialog = new Form2();
// Show testDialog as a modal dialog and determine if DialogResult = OK.
if (testDialog.ShowDialog(this) == DialogResult.OK)
{
// Read the contents of testDialog's TextBox.
this.txtResult.Text = testDialog.TextBox1.Text;
}
else
{
this.txtResult.Text = "Cancelled";
}
testDialog.Dispose();
}

