我可以添加控件到C#的MessageBox? [英] Can I add controls to the C# MessageBox?
问题描述
我可以添加一些自定义的控制标准的消息框读取输入值,例如文本字段的用户名和密码,或者我应该创建自定义的WinForm与确定,取消按钮和文本字段?
Could I add some custom control to the standard Message Box for read input value, for example text fields for user name and password, or I should create custom winform with "Ok,Cancel" buttons and text fields?
推荐答案
创建你自己的。
创建一个自定义模式(或其他方式)输入对话框是不是所有的困难,你可以建立你需要重复使用的可扩展性。
Creating a custom modal (or otherwise) input dialog isn't all that difficult and you can built the extensibility you need for reuse.
public class ValueHolder {
public string SomeInput { get; set; }
public DialogResult Result { get; set; }
}
public class GimmeValues : Form {
//... HAS A TEXTBOX and Okay Buttons...
private GimmeValues() {
okButton.DialogResult = DialogResult.OK;
cancelButton.DialogResult = DialogResult.Cancel;
// ... other stuff
}
public static ValueHolder GetInput(IWin32Window owner) {
using (GimmeValues values = new GimmeValues()) {
DialogResult result = values.ShowDialog(owner);
return new ValueHolder {
SomeInput = values.Textbox1.Text,
Result = result
};
}
}
}
好吧,我只是写,所有在此编辑器所以请原谅所有语法错误。
你可以不喜欢上面的,但它清理干净一点,添加你需要的可扩展性(在按键方面和投入表明你需要等)......那么就这样称呼它而ValueHolder值= GimmeValues .GetInput(本);
,其中这
将重新present的 IWin32Window
。 ..
Okay I just wrote that all in this editor so forgive any syntax mistakes.
You could do something like the above but clean it up a little, add the extensibility you need (in terms of buttons and inputs showing that you need etc)... then just call it like ValueHolder value = GimmeValues.GetInput(this);
where this
would represent an IWin32Window
...
的结果值值
将选定的废话,你可以执行你的逻辑。
The resulting value of value
would be the selected nonsense and you could perform your logic..
if(value.Result == DialogResult.OK && !string.IsNullOrEmpty(value.SomeInput)){
//TODO: Place logic....
}
这篇关于我可以添加控件到C#的MessageBox?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!