protected override void OnKeyDown(KeyEventArgs e) { // Check if we have pressed enter if (e.Key == Key.Enter) { // If we have control pressed... if (Keyboard.Modifiers.HasFlag(ModifierKeys.Control)) { // Add a new line at the point where the cursor is var index = CaretIndex; // Insert the new line Text = Text.Insert(index, Environment.NewLine); // Shift the caret forward to the newline CaretIndex = index + Environment.NewLine.Length; // Mark this key as handled by us e.Handled = true; } else { // Send the message TextSubmitted?.Invoke(this, this.Text); Clear(); } // Mark the key as handled e.Handled = true; } }
protected override void OnKeyDown(KeyEventArgs e) { base.OnKeyDown(e); if (SubmitOnEnter && e.KeyCode == Keys.Enter && !e.Shift) { // Do not add a newline to the text box after clearing e.SuppressKeyPress = true; TextSubmitted?.Invoke(this, EventArgs.Empty); Clear(); } }
private void Input_OnTextEntered(LineEdit.LineEditEventArgs args) { if (!string.IsNullOrWhiteSpace(args.Text)) { TextSubmitted?.Invoke(this, args.Text); _inputHistory.Insert(0, args.Text); } _inputIndex = -1; Input.Clear(); Input.ReleaseFocus(); }
private void Input_OnTextEntered(LineEdit.LineEditEventArgs args) { if (!string.IsNullOrWhiteSpace(args.Text)) { TextSubmitted?.Invoke(this, args.Text); } Input.Clear(); if (ReleaseFocusOnEnter) { Input.ReleaseKeyboardFocus(); } }
private void Input_OnTextEntered(LineEdit.LineEditEventArgs args) { // We set it there to true so it's set to false by TextSubmitted.Invoke if necessary ClearOnEnter = true; if (!string.IsNullOrWhiteSpace(args.Text)) { TextSubmitted?.Invoke(this, args.Text); } if (ClearOnEnter) { Input.Clear(); } if (ReleaseFocusOnEnter) { Input.ReleaseKeyboardFocus(); } }
protected virtual void OnTextEntered(TextSubmittedEventArgs e) { TextSubmitted?.Invoke(this, e); }