# Text editing

The editing point is determined by the caret position and selection in **RadTextBoxControl**. The editing position is visible only if the control is focused.

You can insert text programmatically at concrete position by using the **Insert** method. At that case, the text is inserted at the position determined by the **SelectionStart** property. If the **SelectionLength** property is greater than zero, the inserted text replaces the selected text.

#### Insert string.

```C#
private void Insert()
{
    this.radTextBoxControl1.Text = "Green";
    this.radTextBoxControl1.CaretIndex = 0;
    this.radTextBoxControl1.Insert("John ");
}

```

```VB.NET
Private Sub Insert()
    Me.RadTextBoxControl1.Text = "Green"
    Me.RadTextBoxControl1.CaretIndex = 0
    Me.RadTextBoxControl1.Insert("John ")
End Sub
```

> caption Figure 1: The string is inserted at the specified position.

![WinForms RadTextBoxControl Insert String](https://www.telerik.com/products/winforms/documentation/assets/8bab30ccc5077b6cabeb03f1d918db95/editors-textboxcontrol-text-editing001.png)

Alternatively, you can insert text at the end of the RadTextBoxControl content by using the **AppendText** method:

### Append specific string.

```C#
private void AppendText()
{
    this.radTextBoxControl1.Text = "Samuel";
    this.radTextBoxControl1.AppendText(" Jackson");
}

```

```VB.NET
Private Sub AppendText()
    Me.RadTextBoxControl1.Text = "Samuel"
    Me.RadTextBoxControl1.AppendText(" Jackson")
End Sub
```

> caption Figure 2: The string is added at the end of the existing text.

![WinForms RadTextBoxControl Add String At The End](https://www.telerik.com/products/winforms/documentation/assets/d54f256df6aef79428a0d3589d996dd5/editors-textboxcontrol-text-editing002.png)

You can delete the selected text or character at the caret position by using the **Delete** method:

#### Select and delete a word.

```C#
private void DeleteSelection()
{
    this.radTextBoxControl1.Text = "John Green";
    this.radTextBoxControl1.Select(0, 4);
    this.radTextBoxControl1.Delete();
}

```

```VB.NET
Private Sub DeleteSelection()
    Me.RadTextBoxControl1.Text = "John Green"
    Me.RadTextBoxControl1.[Select](0, 4)
    Me.RadTextBoxControl1.Delete()
End Sub
```

> caption Figure 3: The first word is deleted.

![WinForms RadTextBoxControl Delete First Word](https://www.telerik.com/products/winforms/documentation/assets/65eb91c116a36a06800c163296b663cb/editors-textboxcontrol-text-editing003.png)

Each editing operation raises the **TextChanging** and **TextChanged** events. Notice that you can prevent successful finishing of operation by subscribing to the **TextChanging** event:

#### Cancel the ex changing if the entire text is deleted.

```C#
private void radTextBoxControl1_TextChanging(object sender, Telerik.WinControls.TextChangingEventArgs e)
{
    e.Cancel = string.IsNullOrEmpty(e.NewValue);
}

```

```VB.NET
Private Sub radTextBoxControl1_TextChanging(sender As Object, e As Telerik.WinControls.TextChangingEventArgs)
    e.Cancel = String.IsNullOrEmpty(e.NewValue)
End Sub
```

## See Also

* [AutoComplete](https://www.telerik.com/products/winforms/documentation/controls/editors/textboxcontrol/autocomplete)
* [Caret positioning and selection](https://www.telerik.com/products/winforms/documentation/controls/editors/textboxcontrol/caret-positioning-and-selection)
* [Creating custom blocks](https://www.telerik.com/products/winforms/documentation/controls/editors/textboxcontrol/creating-custom-blocks)
* [Structure](https://www.telerik.com/products/winforms/documentation/controls/editors/textboxcontrol/element-structure-and-document-object-model)
* [Properties and Events](https://www.telerik.com/products/winforms/documentation/controls/editors/textboxcontrol/properties)
* [Text editing](https://www.telerik.com/products/winforms/documentation/controls/editors/textboxcontrol/text-editing)
