InputBox


private System.Windows.Forms.DialogResult InputBox(string title, string promptText, ref string value) 
{
System.Windows.Forms.Form form = new System.Windows.Forms.Form();
System.Windows.Forms.Label label = new System.Windows.Forms.Label();
System.Windows.Forms.TextBox textBox = new System.Windows.Forms.TextBox();
System.Windows.Forms.Button buttonOk = new System.Windows.Forms.Button();
System.Windows.Forms.Button buttonCancel = new System.Windows.Forms.Button();

form.Text = title;
label.Text = promptText;
textBox.Text = value;

buttonOk.Text = "OK";
buttonCancel.Text = "Cancel";
buttonOk.DialogResult = System.Windows.Forms.DialogResult.OK;
buttonCancel.DialogResult = System.Windows.Forms.DialogResult.Cancel;

label.SetBounds(9, 20, 372, 13);
textBox.SetBounds(12, 36, 372, 20);
buttonOk.SetBounds(228, 72, 75, 23);
buttonCancel.SetBounds(309, 72, 75, 23);

label.AutoSize = true;
textBox.Anchor = textBox.Anchor | System.Windows.Forms.AnchorStyles.Right;
buttonOk.Anchor = System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right;
buttonCancel.Anchor = System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right;

form.ClientSize = new System.Drawing.Size(396, 107);
form.Controls.AddRange(new System.Windows.Forms.Control[] { label, textBox, buttonOk, buttonCancel });
form.ClientSize = new System.Drawing.Size(System.Math.Max(300, label.Right + 10), form.ClientSize.Height);
form.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog;
form.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
form.MinimizeBox = false;
form.MaximizeBox = false;
form.AcceptButton = buttonOk;
form.CancelButton = buttonCancel;

System.Windows.Forms.DialogResult dialogResult = form.ShowDialog();
value = textBox.Text;
return dialogResult;
}


© 2019 Better Solutions Limited. All Rights Reserved. © 2019 Better Solutions Limited TopPrevNext