Simulating "delete next word" of MS Word
Blogged by Björn Meyer on November 09, 2005 and tagged with Samples, .NET.
MS Word offers a shortcut (CTRL + DEL) to delete the complete next word. This is quite simple to implement using TX Text Control .NET. We utilize the KeyDown event of TX Text Control to trap the specific keystrokes. Then we use the Find method to search for the next space character. If this space character exists, the text is selected and deleted.
private void textControl1_KeyDown(object sender, System.Windows.Forms.KeyEventArgs e)
{
if(e.Control == true && e.KeyCode == System.Windows.Forms.Keys.Delete)
{
int startPos = textControl1.Selection.Start;
int endPos = textControl1.Find(" ", startPos, TXTextControl.FindOptions.NoMessageBox);
if(endPos != -1)
{
textControl1.Select(startPos, endPos - startPos);
textControl1.Selection.Text = "";
}
else
e.Handled = true;
}
}

