/// <summary> /// If the textBox is disabled, this function does nothing. /// SetDialogState sets the text box to an error state (usually by setting its background colour to pink) if: /// textBox.Text is empty, or /// textBox.Text contains anything other than numbers, commas and whitespace or /// count != uint.MaxValue && there are not count values or /// the values are outside the given range. /// Float values use the '.' character as decimal separator, and are separated by ','s. /// </summary> public static void LeaveFloatRangeTextBox(TextBox textBox, bool canBeEmpty, uint count, float minVal, float maxVal, SetDialogStateDelegate SetDialogState) { if (textBox.Enabled) { if (textBox.Text.Length > 0) { List <string> checkedFloatStrings = GetCheckedFloatStrings(textBox, count, minVal, maxVal); if (checkedFloatStrings != null) { StringBuilder sb = new StringBuilder(); foreach (string floatString in checkedFloatStrings) { sb.Append(", " + floatString); } sb.Remove(0, 3); textBox.Text = sb.ToString(); SetDialogState(textBox, true); } else { SetDialogState(textBox, false); } } else { if (canBeEmpty) { SetDialogState(textBox, true); } else { SetDialogState(textBox, false); } } } }
/// <summary> /// If the textBox is disabled, this function does nothing. /// SetDialogState sets the text box to an error state (usually by setting its background colour to pink) if: /// textBox.Text is empty, or /// textBox.Text contains anything other than numbers, commas and whitespace or /// count != uint.MaxValue and there are not count values or the values are outside the given range. /// </summary> public static void LeaveIntRangeTextBox(TextBox textBox, bool canBeEmpty, uint count, int minVal, int maxVal, SetDialogStateDelegate SetDialogState) { if(textBox.Enabled) { if(textBox.Text.Length > 0) { List<string> checkedIntStrings = GetCheckedIntStrings(textBox, count, minVal, maxVal); if(checkedIntStrings != null) { StringBuilder sb = new StringBuilder(); foreach(string intString in checkedIntStrings) { sb.Append(", " + intString); } sb.Remove(0, 3); textBox.Text = sb.ToString(); SetDialogState(textBox, true); } else { SetDialogState(textBox, false); } } else { if(canBeEmpty) SetDialogState(textBox, true); else SetDialogState(textBox, false); } } }
public BasicChordControl(SetDialogStateDelegate setDialogState) { InitializeComponent(); SetDialogState = setDialogState; }