/// <summary> /// Displays an Input Box with validation. /// </summary> /// <param name="owner">The form's owner.</param> /// <param name="instructions">Instructions to present above the input box.</param> /// <param name="caption">The form's caption</param> /// <param name="defaultValue">The default value to place in the Inbox Box.</param> /// <param name="validator">A validator method that performs validation on the user's input.</param> /// <returns></returns> public static InputBoxResult Show(Form owner, string instructions, string caption, string defaultValue, InputBoxValidatingEventHandler validator) { using (var form = new InputBox()) { form.Owner = owner; form.PromptLabel.Text = instructions; form.Text = caption; form.InputTextBox.Text = defaultValue; form.Validator = validator; var result = form.ShowDialog(); var inputBoxResult = new InputBoxResult(); if (result == DialogResult.OK) { inputBoxResult.Text = form.InputTextBox.Text; inputBoxResult.Ok = true; } return inputBoxResult; } }
private void ButtonCancel_Click(object sender, EventArgs e) { Validator = null; Close(); }
/// <summary> /// Displays an Input Box with validation. /// </summary> /// <param name="owner">The form's owner.</param> /// <param name="instructions">Instructions to present above the input box.</param> /// <param name="caption">The form's caption</param> /// <param name="defaultValue">The default value to place in the Inbox Box.</param> /// <param name="validator">A validator method that performs validation on the user's input.</param> /// <returns></returns> public static InputBoxResult Show(Form owner, string instructions, string caption, string defaultValue, InputBoxValidatingEventHandler validator) { using (var form = new InputBox()) { form.Owner = owner; form.PromptLabel.Text = instructions; form.Text = caption; form.InputTextBox.Text = defaultValue; form.Validator = validator; var result = form.ShowDialog(); var inputBoxResult = new InputBoxResult(); if (result == DialogResult.OK) { inputBoxResult.Text = form.InputTextBox.Text; inputBoxResult.Ok = true; } return(inputBoxResult); } }