Sets the text (forced, even if user is editing it). The value.
(string value)
| 420 | /// </summary> |
| 421 | /// <param name="value">The value.</param> |
| 422 | [NoAnimate] |
| 423 | public void SetText(string value) |
| 424 | { |
| 425 | // Prevent from null problems |
| 426 | if (value == null) |
| 427 | value = string.Empty; |
| 428 | |
| 429 | // Filter text |
| 430 | if (value.IndexOf('\r') != -1) |
| 431 | value = value.Replace("\r", ""); |
| 432 | |
| 433 | // Filter text (handle backspace control character) |
| 434 | if (value.IndexOf(DelChar) != -1) |
| 435 | value = value.Replace(DelChar.ToString(), ""); |
| 436 | |
| 437 | // Clamp length |
| 438 | if (value.Length > MaxLength && MaxLength != -1) |
| 439 | value = value.Substring(0, MaxLength); |
| 440 | |
| 441 | // Ensure to use only single line |
| 442 | if (_isMultiline == false && value.Length > 0) |
| 443 | { |
| 444 | // Extract only the first line |
| 445 | value = value.GetLines()[0]; |
| 446 | } |
| 447 | |
| 448 | if (_text.Equals(value, StringComparison.Ordinal)) |
| 449 | return; |
| 450 | |
| 451 | if (CharactersToAllow != AllowableCharacters.All) |
| 452 | { |
| 453 | if (CharactersToAllow == AllowableCharacters.None) |
| 454 | { |
| 455 | value = string.Empty; |
| 456 | } |
| 457 | else |
| 458 | { |
| 459 | if (!CharactersToAllow.HasFlag(AllowableCharacters.Letters)) |
| 460 | { |
| 461 | if (value != null) |
| 462 | value = new string(value.Where(c => !char.IsLetter(c)).ToArray()); |
| 463 | } |
| 464 | if (!CharactersToAllow.HasFlag(AllowableCharacters.Numbers)) |
| 465 | { |
| 466 | if (value != null) |
| 467 | value = new string(value.Where(c => !char.IsNumber(c)).ToArray()); |
| 468 | } |
| 469 | if (!CharactersToAllow.HasFlag(AllowableCharacters.Symbols)) |
| 470 | { |
| 471 | if (value != null) |
| 472 | value = new string(value.Where(c => !char.IsSymbol(c)).ToArray()); |
| 473 | } |
| 474 | value ??= string.Empty; |
| 475 | } |
| 476 | } |
| 477 | |
| 478 | Deselect(); |
| 479 | ResetViewOffset(); |