private static int _setPositionFoundOfficialSymbol(Control control, string message, bool isPositionFoundOfficialSymbol, PositionFoundOfficialSymbol positionFoundOfficialSymbol, string foundOfficialSymbol) { var position = -1; if (!string.IsNullOrEmpty(message)) { var text = ""; var isMessageNoEqualsFoundOfficialSymbol = !string.Equals(message, foundOfficialSymbol, StringComparison.OrdinalIgnoreCase); var foundOfficialSymbolLength = foundOfficialSymbol.Length; if (isMessageNoEqualsFoundOfficialSymbol && isPositionFoundOfficialSymbol) { if ((positionFoundOfficialSymbol & PositionFoundOfficialSymbol.Start) == PositionFoundOfficialSymbol.Start) { if ((message.Length < foundOfficialSymbolLength) || (message.IndexOf(foundOfficialSymbol, 0, foundOfficialSymbolLength, StringComparison.OrdinalIgnoreCase) == -1)) { text = foundOfficialSymbol; } } } text += message; position = text.Length; if (isMessageNoEqualsFoundOfficialSymbol && isPositionFoundOfficialSymbol) { if ((positionFoundOfficialSymbol & PositionFoundOfficialSymbol.End) == PositionFoundOfficialSymbol.End) { if ((message.Length < foundOfficialSymbolLength) || (message.IndexOf(foundOfficialSymbol, message.Length - foundOfficialSymbolLength, foundOfficialSymbolLength, StringComparison.OrdinalIgnoreCase) == -1)) { text += foundOfficialSymbol; } } } control.Text = text; } return(position); }
//--------------------------------------------------------------------- private bool _setPositionFoundOfficialSymbolAndCursor(TextBoxBase textBox, string message, PositionFoundOfficialSymbol positionFoundOfficialSymbol) { var result = false; if (string.IsNullOrWhiteSpace(textBox.Text) || textBox.Text.Length == textBox.SelectionLength) { result = true; var position = _setPositionFoundOfficialSymbol(textBox, message, _isSetFoundOfficialSymbol, positionFoundOfficialSymbol, _foundOfficialSymbolMessage); _setPositionCursor(textBox, position); } return(result); }