private async Task ExecuteDelayedOverwrite() { await Task.Run(async() => { var delay = TimeSpan.FromMilliseconds(500); await Task.Delay(delay); if (DateTime.Now - _lastUpdated < TimeSpan.FromMilliseconds(500)) { return; } #if WINDOWS_STORE || WINDOWS_PHONE_APP await ApplicationSpace.CurrentDispatcher.RunAsync(CoreDispatcherPriority.Normal, #elif WINDOWS_PHONE ApplicationSpace.CurrentDispatcher.BeginInvoke( #endif () => { var selectionStart = InputBox.SelectionStart; InputBox.Text = Regex.Replace(InputBox.Text, ".", PasswordChar.ToString()); InputBox.SelectionStart = selectionStart; }); }); }
private void ReCalculatePasswordChar(bool using_password) { if (using_password && document != null) { if (is_empty_mask) { document.PasswordChar = PasswordChar.ToString(); } else { document.PasswordChar = string.Empty; } } }
private void PUPasswordBox_TextInput(object sender, TextCompositionEventArgs e) { var currentCursor = SelectionStart; if (SelectionLength != 0) { var length = SelectionLength; Text = Text.Remove(currentCursor, length); Password = Password.Remove(currentCursor, length); } Text = Text.Insert(currentCursor, PasswordChar.ToString()); Password = Password.Insert(currentCursor, e.Text); Select(currentCursor + 1, 0); e.Handled = true; }
void InputBoxTextChanged(object sender, TextChangedEventArgs e) { var diff = InputBox.Text.Length - _inputText.Length; // handle text removes if (diff < 0) { diff *= -1; // adding one since the selection has moved var startIndex = InputBox.SelectionStart + 1 - diff; if (startIndex < 0) { startIndex = 0; } _inputText.Remove(startIndex, diff); Value = _inputText.ToString(); } else if (diff > 0) { // get new chars // append onto SB // set value // update InputBox with * var selectionStart = InputBox.SelectionStart; var selectionIndex = selectionStart - 1; var newChars = InputBox.Text.Substring(selectionIndex, diff); _inputText.Insert(selectionIndex, newChars); Value = _inputText.ToString(); if (InputBox.Text.Length >= 2) { var replacementString = new StringBuilder(); replacementString.Insert(0, PasswordChar.ToString(CultureInfo.InvariantCulture), InputBox.Text.Length - 1); replacementString.Insert(selectionIndex, newChars); InputBox.Text = replacementString.ToString(); } InputBox.SelectionStart = selectionStart; } }
public override int GetHashCode() { unchecked { var hashCode = MinorVersion.GetHashCode(); hashCode = (hashCode * 397) ^ MajorVersion.GetHashCode(); hashCode = (hashCode * 397) ^ (PropMask?.GetHashCode() ?? 0); hashCode = (hashCode * 397) ^ (ForeColor?.GetHashCode() ?? 0); hashCode = (hashCode * 397) ^ (BackColor?.GetHashCode() ?? 0); hashCode = (hashCode * 397) ^ (int)VariousPropertyBits; hashCode = (hashCode * 397) ^ (Caption?.GetHashCode() ?? 0); hashCode = (hashCode * 397) ^ (int)PicturePosition; hashCode = (hashCode * 397) ^ (int)MousePointer; hashCode = (hashCode * 397) ^ (Accelerator?.GetHashCode() ?? 0); hashCode = (hashCode * 397) ^ (Size?.GetHashCode() ?? 0); hashCode = (hashCode * 397) ^ (Picture?.Length.GetHashCode() ?? 0); hashCode = (hashCode * 397) ^ (MouseIcon?.Length.GetHashCode() ?? 0); hashCode = (hashCode * 397) ^ (TextProps?.GetHashCode() ?? 0); hashCode = (hashCode * 397) ^ (int)MaxLength; hashCode = (hashCode * 397) ^ (int)BorderStyle; hashCode = (hashCode * 397) ^ (ScrollBars?.GetHashCode() ?? 0); hashCode = (hashCode * 397) ^ DisplayStyle.GetHashCode(); hashCode = (hashCode * 397) ^ (PasswordChar?.GetHashCode() ?? 0); hashCode = (hashCode * 397) ^ (int)ListWidth; hashCode = (hashCode * 397) ^ BoundColumn.GetHashCode(); hashCode = (hashCode * 397) ^ TextColumn.GetHashCode(); hashCode = (hashCode * 397) ^ ColumnCount.GetHashCode(); hashCode = (hashCode * 397) ^ ListRows.GetHashCode(); hashCode = (hashCode * 397) ^ ColumnInfoCount.GetHashCode(); hashCode = (hashCode * 397) ^ MatchEntry.GetHashCode(); hashCode = (hashCode * 397) ^ ListStyle.GetHashCode(); hashCode = (hashCode * 397) ^ ShowDropButtonWhen.GetHashCode(); hashCode = (hashCode * 397) ^ DropButtonStyle.GetHashCode(); hashCode = (hashCode * 397) ^ MultiSelect.GetHashCode(); hashCode = (hashCode * 397) ^ (BorderColor?.GetHashCode() ?? 0); hashCode = (hashCode * 397) ^ (int)SpecialEffect; hashCode = (hashCode * 397) ^ (Value?.GetHashCode() ?? 0); hashCode = (hashCode * 397) ^ (GroupName?.GetHashCode() ?? 0); hashCode = (hashCode * 397) ^ (Remainder?.Length.GetHashCode() ?? 0); return(hashCode); } }
private async void InputBoxTextChanged(object sender, TextChangedEventArgs e) { var diff = InputBox.Text.Length - _inputText.Length; // handle text removes if (diff < 0) { diff *= -1; // adding one since the selection has moved var startIndex = InputBox.SelectionStart + 1 - diff; if (startIndex < 0) { startIndex = 0; } _inputText.Remove(startIndex, diff); Value = _inputText.ToString(); } else if (diff > 0) { // get new chars // append onto SB // set value // update InputBox with * var selectionStart = InputBox.SelectionStart; var selectionIndex = selectionStart - diff; var newChars = InputBox.Text.Substring(selectionIndex, diff); _inputText.Insert(selectionIndex, newChars); Value = _inputText.ToString(); // Paste operation if (diff > 1) { var replacementString = new StringBuilder(); replacementString.Insert(0, PasswordChar.ToString(), InputBox.Text.Length); InputBox.Text = replacementString.ToString(); } else { if (InputBox.Text.Length >= 2) { var replacementString = new StringBuilder(); replacementString.Insert(0, PasswordChar.ToString(), InputBox.Text.Length - diff); replacementString.Insert(selectionIndex, newChars); InputBox.Text = replacementString.ToString(); } await ExecuteDelayedOverwrite(); _lastUpdated = DateTime.Now; } InputBox.SelectionStart = selectionStart; } }
private void PUPasswordBox_PreviewKeyDown(object sender, System.Windows.Input.KeyEventArgs e) { //禁止任何与Control键有关的事(除了全选) if (Keyboard.IsKeyDown(Key.LeftCtrl) && !Keyboard.IsKeyDown(Key.A)) { e.Handled = true; return; } var currentCursor = SelectionStart; switch (e.Key) { case Key.Back: if (Text.Length > 0 && currentCursor > 0 && SelectionLength == 0) { Text = Text.Remove(currentCursor - 1, 1); Password = Password.Remove(currentCursor - 1, 1); if (currentCursor > 0) { Select(currentCursor - 1, 0); } } else if (SelectionLength > 0) { var length = SelectionLength; Text = Text.Remove(currentCursor, length); Password = Password.Remove(currentCursor, length); if (currentCursor - length > 0) { Select(currentCursor - length + 1, 0); } } //批量选择情况下 break; case Key.Delete: if (currentCursor < Text.Length) { Text = Text.Remove(currentCursor, 1); Password = Password.Remove(currentCursor, 1); Select(currentCursor, 0); } break; case Key.Space: if (SelectionLength != 0) { Text = Text.Remove(currentCursor, SelectionLength); Password = Password.Remove(currentCursor, SelectionLength); } Text = Text.Insert(currentCursor, PasswordChar.ToString()); Password = Password.Insert(currentCursor, " "); Select(currentCursor + 1, 0); break; default: return; } e.Handled = true; }