Products Technologies Demo Docs Blog Support Company

Windows Forms: Removing the Next Word Right to the Input Position on CTRL + DEL

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!

Windows Forms: Removing the Next Word Right to the Input Position on CTRL + DEL

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

Stay in the loop!

Subscribe to the newsletter to receive the latest updates.

Windows Forms

Text Control combines the power of a reporting tool and an easy-to-use WYSIWYG word processor - fully programmable and embeddable in your Windows Forms application. TX Text Control .NET for Windows Forms is a royalty-free, fully programmable rich edit control that offers developers a broad range of word processing features in a reusable component for Visual Studio.

See Windows Forms products

Related Posts

ASP.NETWindows FormsWPF

TX Text Control 33.0 SP3 is Now Available: What's New in the Latest Version

TX Text Control 33.0 Service Pack 3 is now available, offering important updates and bug fixes for all platforms. If you use TX Text Control in your document processing applications, this service…


ASP.NETWindows FormsWPF

TX Text Control 33.0 SP2 is Now Available: What's New in the Latest Version

TX Text Control 33.0 Service Pack 2 is now available, offering important updates and bug fixes for all platforms. If you use TX Text Control in your document processing applications, this service…


ASP.NETWindows FormsWPF

Document Lifecycle Optimization: Leveraging TX Text Control's Internal Format

Maintaining the integrity and functionality of documents throughout their lifecycle is paramount. TX Text Control provides a robust ecosystem that focuses on preserving documents in their internal…


ActiveXASP.NETWindows Forms

Expert Implementation Services for Legacy System Modernization

We are happy to officially announce our partnership with Quality Bytes, a specialized integration company with extensive experience in modernizing legacy systems with TX Text Control technologies.


ActiveXASP.NETWindows Forms

Service Pack Releases: What's New in TX Text Control 33.0 SP1 and 32.0 SP5

TX Text Control 33.0 Service Pack 1 and TX Text Control 32.0 Service Pack 5 have been released, providing important updates and bug fixes across platforms. These service packs improve the…