New to Telerik UI for WinFormsStart a free 30-day trial

Text editing

Updated over 6 months ago

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 ");
}

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

WinForms RadTextBoxControl Insert String

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");
}

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

WinForms RadTextBoxControl Add String At The End

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();
}

Figure 3: The first word is deleted.

WinForms RadTextBoxControl Delete First Word

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);
}

See Also

In this article
Append specific string.See Also
Not finding the help you need?
Contact Support