# Keyboard Shortcuts

> All built-in keys of the Windows Forms TextControl, a KeyDown handler for Ctrl+F, Ctrl+H and Insert, and a KeyPress handler that turns Enter into a line break.

- **Product:** TX Text Control .NET for Windows Forms
- **Section:** Documentation
- **Kind:** Topic
- **Path:** TX Text Control .NET for Windows Forms > Document Editor > Editing Text > Keyboard Shortcuts
- **2753 words**
- **Web URL:** https://docs.textcontrol.com/tx-text-control-dotnet-winforms/document-editor/editing-text/keyboard-shortcuts/
- **LLMs URL:** https://docs.textcontrol.com/tx-text-control-dotnet-winforms/document-editor/editing-text/keyboard-shortcuts/llms.txt
- **LLMs-Full URL:** https://docs.textcontrol.com/tx-text-control-dotnet-winforms/document-editor/editing-text/keyboard-shortcuts/llms-full.txt

---

A `TextControl` on a Windows Forms form responds to a fixed set of keys as soon as it has the focus: the arrow keys and their combinations move the caret, Ctrl+C and Ctrl+V use the clipboard, Ctrl+Enter starts a new page. The tables below list every built-in assignment, for your own reference and for the help of your application. The last section adds shortcuts of your own, such as Ctrl+F for the Find dialog box.

The mouse actions, such as a double-click to select a word, are listed on [Selections and Caret Position](https://docs.textcontrol.com/tx-text-control-dotnet-winforms/document-editor/editing-text/selections/#select-text-with-the-mouse-and-keyboard).

### Move the Caret

| Keys | Action |
|---|---|
| Left Arrow, Right Arrow | Moves the caret one character to the left or right |
| Up Arrow, Down Arrow | Moves the caret one line up or down |
| Ctrl+Left Arrow | Moves the caret to the beginning of the current word |
| Ctrl+Right Arrow | Moves the caret to the beginning of the next word |
| Home | Moves the caret to the beginning of the line |
| End | Moves the caret to the end of the line |
| Ctrl+Home | Moves the caret to the start of the text |
| Ctrl+End | Moves the caret to the end of the text |
| Page Up, Page Down | Scrolls up or down by the height of the visible area minus one line, if there is a vertical scroll bar |
| Shift+Page Up, Shift+Page Down | Scrolls the document horizontally |
| Ctrl+Page Up, Ctrl+Page Down | Zooms the document in or out |

Holding down Shift while pressing a key that moves the caret extends the selection to the new caret position. Shift+Ctrl+End, for example, selects everything from the caret to the end of the text.

### Edit Text

| Keys | Action |
|---|---|
| Shift+Enter | Inserts a line break without starting a new paragraph |
| Ctrl+Enter | Inserts a page break |
| Ctrl+Shift+Enter | Inserts a column break, so that the text continues in the next column of a multi-column section |
| Ctrl+Shift+Spacebar | Inserts a non-breaking space |
| Delete | Deletes the selected text |
| Ctrl+Backspace, Shift+Backspace | Deletes the previous word |
| Ctrl+C | Copies the selected text to the clipboard |
| Ctrl+X | Copies the selected text to the clipboard and deletes it |
| Ctrl+V | Pastes the content of the clipboard in place of the selection |
| Ctrl+Z | Undoes the last action |
| Ctrl+Y | Restores the last undone action |

[Clipboard Operations](https://docs.textcontrol.com/tx-text-control-dotnet-winforms/document-editor/editing-text/clipboard/llms-full.txt) and [Undo and Redo](https://docs.textcontrol.com/tx-text-control-dotnet-winforms/document-editor/editing-text/undo-redo/llms-full.txt) show the methods behind the clipboard and undo keys.

### Insert Hyphens and Dashes

| Keys | Inserts | Word may be divided there |
|---|---|---|
| Hyphen (-) | A hyphen or minus sign | Yes |
| Ctrl+Hyphen | An end-of-line hyphen, which is not visible unless the word is divided at that point | Yes |
| Ctrl+Shift+Hyphen | A hyphen for compound words that keeps the parts on one line | No |
| Ctrl+Minus on the numeric keypad | An en dash | Yes |
| Ctrl+Alt+Minus on the numeric keypad | An em dash | Yes |

Automatic hyphenation is described on [Spell Checking and Hyphenation](https://docs.textcontrol.com/tx-text-control-dotnet-winforms/document-editor/spell-checking/llms-full.txt).

### Keys in Tables

| Keys | Action |
|---|---|
| Tab | Selects the next table cell. In the last cell of a table, it adds a new row at the end of the table. |
| Shift+Tab | Selects the previous table cell |
| Ctrl+Tab | Inserts a tab character in the cell |
| Enter | At the first input position of a document that begins with a table, inserts an empty line in front of the table |

Outside of tables, the Tab key depends on [AcceptsTab](https://docs.textcontrol.com/tx-text-control-dotnet-winforms/reference/txtextcontrol/textcontrol/acceptstab-property/llms-full.txt): with `true`, it types a tab character; with `false`, it moves the focus to the next control in the tab order of the form.

Form fields have keys of their own, for example the Spacebar to check a check box or open a drop-down list, and Tab to go to the next field in a protected form. They are listed on [Form Fields and Conditional Instructions](https://docs.textcontrol.com/tx-text-control-dotnet-winforms/document-editor/form-fields/llms-full.txt).

### Add Your Own Shortcuts

Every key press raises the `KeyDown` event that `TextControl` inherits from the Windows Forms `Control` class. A handler of this event can call any method of the editor for a key combination and mark the key as handled, so that the editor ignores it. The following code in *Form1.cs* opens the Find and Replace dialog boxes with Ctrl+F and Ctrl+H, selects all text with Ctrl+A and switches between insert and overwrite mode with the Insert key:

```csharp
using System;
using System.Windows.Forms;
using TXTextControl;

public partial class Form1 : Form
{
    public Form1()
    {
        InitializeComponent();
        textControl1.KeyDown += TextControl1_KeyDown;
    }

    private void TextControl1_KeyDown(object sender, KeyEventArgs e)
    {
        // Ctrl+F: open the built-in Find dialog box
        if (e.Control && !e.Alt && !e.Shift && e.KeyCode == Keys.F)
        {
            textControl1.Find();
            e.Handled = true;
        }
        // Ctrl+H: open the built-in Replace dialog box
        else if (e.Control && !e.Alt && !e.Shift && e.KeyCode == Keys.H)
        {
            textControl1.Replace();
            e.Handled = true;
        }
        // Ctrl+A: select the whole text
        else if (e.Control && !e.Alt && !e.Shift && e.KeyCode == Keys.A)
        {
            textControl1.SelectAll();
            e.Handled = true;
        }
        // Insert: switch between inserting and overwriting text
        else if (e.Modifiers == Keys.None && e.KeyCode == Keys.Insert)
        {
            textControl1.InsertionMode = textControl1.InsertionMode == InsertionMode.Insert
                ? InsertionMode.Overwrite
                : InsertionMode.Insert;
            e.Handled = true;
        }
    }
}
```

Keep the `namespace` that Visual Studio created around the class. Run the application and press Ctrl+F: the Find dialog box opens.

The code works as follows:

- `e.Control`, `e.Alt` and `e.Shift` tell which modifier keys are held down, and `e.KeyCode` which key was pressed. The checks make sure that Ctrl+Shift+F, for example, doesn't trigger the same command.
- [Find](https://docs.textcontrol.com/tx-text-control-dotnet-winforms/reference/txtextcontrol/textcontrol/find-method/llms-full.txt) and [Replace](https://docs.textcontrol.com/tx-text-control-dotnet-winforms/reference/txtextcontrol/textcontrol/replace-method/llms-full.txt) without parameters open the built-in dialog boxes, and [SelectAll](https://docs.textcontrol.com/tx-text-control-dotnet-winforms/reference/txtextcontrol/textcontrol/selectall-method/llms-full.txt) selects the whole text.
- [InsertionMode](https://docs.textcontrol.com/tx-text-control-dotnet-winforms/reference/txtextcontrol/textcontrol/insertionmode-property/llms-full.txt) is `Insert` when typed text is inserted and `Overwrite` when it replaces the text at the input position.
- `e.Handled = true` tells the editor that the key has been processed, so its own handling of the key is skipped.

The TX Words sample of the setup, in *%USERPROFILE%\\Documents\\TX Text Control 34.0.NET for Windows Forms\\CSharp\\TX Words\\Shortcuts*, handles Ctrl+O, Ctrl+S and Ctrl+P for opening, saving and printing the same way. The blog article [Windows Forms: Removing the Next Word Right to the Input Position on CTRL + DEL](https://www.textcontrol.com/blog/2016/01/22/windows-forms-removing-the-next-word-right-to-the-input-position-on-ctrl-del/) adds Ctrl+Delete to delete the next word.

### Insert a Line Break With Enter

Some applications, such as an editor for address blocks or table cells, need Enter to start a new line inside the same paragraph, as Shift+Enter does. The `KeyPress` event, also inherited from `Control`, receives the Enter key as the carriage return character `'\r'`. The handler below replaces it with a line break, which is the vertical tab character `"\v"` in the text of a `TextControl`:

```csharp
// In the constructor, after InitializeComponent
textControl1.KeyPress += TextControl1_KeyPress;

private void TextControl1_KeyPress(object sender, KeyPressEventArgs e)
{
    if (e.KeyChar == '\r')
    {
        // Skip the new paragraph and insert a line break instead
        e.Handled = true;
        textControl1.Selection.Text = "\v";
    }
}
```

[Selection.Text](https://docs.textcontrol.com/tx-text-control-dotnet-winforms/reference/txtextcontrol/selection/text-property/llms-full.txt) replaces the selected text, or inserts at the input position when nothing is selected.

### Next Steps

- [Selections and Caret Position](https://docs.textcontrol.com/tx-text-control-dotnet-winforms/document-editor/editing-text/selections/llms-full.txt): the mouse actions and the selection in code.
- [Search and Replace](https://docs.textcontrol.com/tx-text-control-dotnet-winforms/document-editor/editing-text/search-replace/llms-full.txt): the Find and Replace dialog boxes and sidebars.
- [Events](https://docs.textcontrol.com/tx-text-control-dotnet-winforms/document-editor/events/llms-full.txt): the other events of the editor.

---

## Nearby

- **Previous:** [Drag and Drop](https://docs.textcontrol.com/tx-text-control-dotnet-winforms/document-editor/editing-text/drag-drop/llms-full.txt)
- **Next:** [Text and Paragraph Formatting](https://docs.textcontrol.com/tx-text-control-dotnet-winforms/document-editor/formatting/llms-full.txt)
