MS Word provides a functionality to remove the next word at the current input position by pressing the key combination CTRL + DEL. TX Text Control implements many pre-defined key combinations and mouse selections with the Smart Selection Interface.

But thanks to the flexible API and the complete event set, additional combinations can be easily implemented. The following code shows how to trap the key combination CTRL + DEL to remove the next word right to the input position.

Happy coding!

private void textControl1_KeyDown(object sender, KeyEventArgs e)
{
if (e.Control && e.KeyCode == Keys.Delete)
{
// get the current paragraph at the input position
TXTextControl.Paragraph curParagraph =
textControl1.Paragraphs.GetItem(textControl1.Selection.Start);
// return the text beginning at the input position
// until the end of the paragraph
string sParagraph = curParagraph.Text.Substring(
textControl1.Selection.Start - curParagraph.Start + 1);
// search for delimiters and return the positions
List<int> indexes = Regex.Matches(sParagraph, @"[^\w]+").Cast<Match>()
.Select(m => m.Index)
.ToList();
// if delimiters are found, select the text until the next
// delimiter and remove the text
if (indexes.Count > 0)
{
textControl1.Selection.Length = indexes[0] + 1;
textControl1.Selection.Text = "";
// cancel the original event handling
e.Handled = true;
}
}
}
view raw tx.cs hosted with ❤ by GitHub