private void IncreaseMask(int position) { var provider = MaskProvider; var str = provider.ToDisplayString().Insert(position, PromptChar.ToString()).Replace(" ", string.Empty); Mask = FormatMask(Mask.Insert(position, PromptChar.ToString())); Text = str; CaretIndex = GetDecimalSeparatorPosition(Mask) - 1; }
private void DecreaseMask(int position, int length) { var decPos = GetDecimalSeparatorPosition(Mask); var str = MaskProvider.ToDisplayString(); if (position > decPos) { Text = str.Remove(position, length).Insert(position, 0.ToString("D" + length)); CaretIndex = position; return; } if (position + length > decPos) { var decLength = position + length - decPos - 1; var decPosition = decPos + 1; str = str.Remove(decPosition, decLength).Insert(decPosition, 0.ToString("D" + decLength)); length = decPos - position; } if (length > 0) { str = str.Remove(position, length).Replace(" ", string.Empty); if (str.Length == 0) { str = PromptChar.ToString(); } var mask = FormatMask(Mask.Remove(position, length)); if (mask.Length == 0 || mask.StartsWith(".")) { if (mask.StartsWith(".")) { str = PromptChar + str; } mask = PromptChar + mask; } Mask = mask; Text = str; } CaretIndex = position; }