摘要:Customer InputBox
class InputBox
{
public static string Show(string title, string promptText)
{
string value = "";
var label = new Label()
{
Text = promptText,
};
label.SetBounds(9, 20, 280, 13);
var textBox = new TextBox();
textBox.SetBounds(12, 36, 280, 20);
var buttonOk = new Button()
{
Text = "OK",
DialogResult = DialogResult.OK,
};
buttonOk.SetBounds(140, 72, 75, 23);
var buttonCancel = new Button()
{
Text = "Cancel",
DialogResult = DialogResult.Cancel,
};
buttonCancel.SetBounds(220, 72, 75, 23);
var form = new Form()
{
Text = title,
FormBorderStyle = FormBorderStyle.FixedDialog,
MinimizeBox = false,
MaximizeBox = false,
ClientSize = new Size(300, 100),
StartPosition = FormStartPosition.CenterScreen,
};
form.Controls.AddRange(new Control[] { textBox, label, buttonOk, buttonCancel });
if (form.ShowDialog() == DialogResult.OK)
{
value = textBox.Text;
}
return value;
}
}
string msg = InputBox.Show("test", "Message");
MessageBox.Show(msg);