Sample: Custom Smart Selections with TX Text Control .NET
In a recent blog entry, I gave an overview of special mouse and keyboard assignments that assist with typical selection tasks. When double-clicking a word, TX Text Control selects the whole word and respects text delimiters such as periods or commas automatically. But sometimes, a delimiter should not be respected, but included when used as part of a decimal number, an URL or an e-mail address. In such situations, we can easily use the DoubleClick event of TextControl to inject our custom…

In a recent blog entry, I gave an overview of special mouse and keyboard assignments that assist with typical selection tasks. When double-clicking a word, TX Text Control selects the whole word and respects text delimiters such as periods or commas automatically. But sometimes, a delimiter should not be respected, but included when used as part of a decimal number, an URL or an e-mail address.
In such situations, we can easily use the DoubleClick event of TextControl to inject our custom selection behaviour. In this sample, I would like to show how a complete sequence of characters delimited by spaces can be selected. The algorithm works as follows:
- Find the next space character before the current input position.
- Find the next space character after the input position.
- Select the range between these positions.
TX Text Control provides some powerful properties to get the required positions in the current Line. When double-clicking somewhere into the string $399.99, this whole price is selected:

The same custom selection works for date values, URLs or e-mail addresses as well:

Download and Fork This Sample on GitHub
We proudly host our sample code on github.com/TextControl.
Please fork and contribute.
Requirements for this sample
- Visual Studio 2008 or better
- TX Text Control .NET for Windows Forms (trial sufficient)
Related Posts
Create a Table of Contents in Windows Forms using C#
This article explains how to create a table of contents in Windows Forms using the ribbon or programmatically. Creating a table of contents is required to organize large documents.
Official TX Text Control .NET Sample Applications Are Now Hosted on GitHub
This article gives a quick overview of the new repositories, their structure and our plans for the future.
ASP.NETJavaScriptDocument Editor
Detect Toggle Button Changes Using a MutationObserver
This article shows how to detect changes of toggle buttons in the ribbon of the web editor using a MutationObserver. The state of a toggle button in the ribbon visualizes the state of a certain…
Two Ways to Restart Numbered Lists in TX Text Control
In TX Text Control, numbered lists are continued by default and need to be reset when required. There is more than one way if you want to restart numbered lists in a document. In this article, two…
Zoom Tricks: Disabling CTRL + MOUSE WHEEL and More
This article shows how to disable CTRL + MOUSE WHEEL, implement zooming with keyboard and reset the zoom factor to its default value.