Text Editing Overview
- 3 minutes to read
Most of the editors in the XtraEditors library are derived from the TextEdit class, and thus, provide text boxes. This topic describes how to use text boxes, apply selections and work with the Clipboard. This functionality is implemented solely by the TextEdit class. Note that descendants may only use part of this functionality or may not use it at all.
Text Editing Basics
End-users can navigate through the text using either the keyboard or the mouse. The LEFT and UP arrow keys move the caret forward while the RIGHT and DOWN arrow keys move the caret backwards. If the CTRL key is pressed when pressing an arrow key, the caret moves to the next or previous space character found. The HOME and END keys can be used to move the caret before the first character or after the last one respectively. To change the caret position via code, use the TextEdit.SelectionStart property.
All common text editing features are available in text editors. This includes typing characters, deleting them using the BACKSPACE or DEL keys, etc. Note that end-users can press the CTRL+DEL combination to remove the editor’s entire content.
To change the editor value via code, you should assign a value to the BaseEdit.EditValue or BaseEdit.Text property. Changing an editor’s value raises its RepositoryItem.EditValueChanging and BaseEdit.EditValueChanged events. Handle them to control user input.
You can limit the number of characters that can be entered by end-users by using the RepositoryItemTextEdit.MaxLength property. You can apply an editor mask for more control of end-user input. This will restrict end-users to the characters allowed by the mask. Masks can be applied to editors using the RepositoryItemTextEdit.Mask property. For detailed information on applying masks, refer to the Input Mask topic.
A text editor can be used for entering passwords. To do so, set the RepositoryItemMemoEdit.UseSystemPasswordChar property to true, or assign a character to the RepositoryItemTextEdit.PasswordChar property.
Selections
Selections can be applied using the mouse and keyboard. To select a text portion within a text box, end-users must place the caret at the start of the text to be selected, and then use the navigation keys while pressing the SHIFT key (please refer above for details about the navigation keys available). To select the editor’s entire content, or to remove the selection, use the F2 key. To select a word (a sequence of characters between two spaces), end-users should double-click it.
If you need to select a portion of text via code, use the TextEdit.SelectionStart and TextEdit.SelectionLength properties. To select the editor’s entire content, or to clear the selection, use the TextEdit.SelectAll and TextEdit.DeselectAll methods. You can access the selected text using the TextEdit.SelectedText property. Strings assigned to this property will replace the current selection.
Built-In Context Menu (Undo and Clipboard Operations)
Text editors offer a built-in context menu that enables end-users to undo the last action, perform Clipboard operations and select the editor’s entire content. All these actions can also be performed using shortcuts or code.
Menu Item | Action | Shortcut | Member |
---|---|---|---|
Undo | Restores the previous value. | CTRL+Z | TextEdit.Undo |
Copy | Copies the selected text to the Clipboard. | CTRL+C, CTRL+INS | TextEdit.Copy |
Paste | Pastes the Clipboard content. | CTRL+V, SHIFT+INS | TextEdit.Paste |
Cut | Copies the selected text to the Clipboard and removes it. | CTRL+X, SHIFT+DEL | TextEdit.Cut |
Delete | Deletes the selected text. | DEL, BACKSPACE | TextEdit.SelectedText |
Select All | Selects all text within the editor. | CTRL+A | TextEdit.SelectAll |