Tag Archives: TextBox

Make a TextBox preview extender provider in C#

This example shows how to convert the TextBox preview techniques described in the last few posts into an extender provider. The previous examples showed the basic technique, but they were hard-wired to specific TextBox controls so they weren’t very flexible. … Continue reading

Posted in controls, extensions, user interface | Tagged , , , , , , , , , , , , , , | Leave a comment

Make the user enter a float in C#

The posts Preview TextBox changes in C# and Preview TextBox changes in C#, Part 2 show how you can make a TextBox accept only integers. This example is similar except it makes a TextBox only accept floats. This change is … Continue reading

Posted in controls, user interface | Tagged , , , , , , , , , , , , , , , | Leave a comment

Preview TextBox changes in C#, Part 2

Part 1 of this post explained how the example previews changes made by keyboard events. It then accepts or cancels the changes depending on whether the TextBox control’s new value is a valid integer (or the start of one as … Continue reading

Posted in controls, user interface | Tagged , , , , , , , , , , , , | Leave a comment

Preview TextBox changes in C#

One of the more annoying omissions from the Windows Forms controls is a way to preview changes to a TextBox before they occur. For example, suppose you want the user to enter a floating point value in a TextBox. The … Continue reading

Posted in controls, user interface | Tagged , , , , , , , , , , , , | 2 Comments

Make Ctrl+A select all of the text in a TextBox in C#

Often it’s convenient for the user to be able to press Ctrl+A to select all of the text in the TextBox that has the focus. Strangely that’s not the default behavior for the TextBox. Perhaps the TextBox doesn’t handle Ctrl+A … Continue reading

Posted in controls, user interface | Tagged , , , , , , , , , , | Leave a comment

Make a TextBox with auto-complete in C#

It’s not too hard to make a TextBox provide an auto-complete feature. In fact, the TextBox control offers three auto-complete styles. This example demonstrates those styles. To provide auto-complete, you need to set the following three TextBox properties. AutoCompleteMode – … Continue reading

Posted in controls, user interface | Tagged , , , , , , , , , | Leave a comment

Remove a TextBox control’s context menu in C#

Normally a TextBox control has a context menu that appears when you right-click it, but what if you don’t want that context menu? I mean, really. Am I required to have “Show Unicode control characters” and “Open IME” on every … Continue reading

Posted in controls | Tagged , , , , , , , , , , | 1 Comment

Make a TextBox convert text into proper case in C#

The example Convert a string to proper case (title case) in C# uses a CultureInfo object’s TextInfo property to convert text into proper case (or title case). There are a couple of tricks and potential problems that you need to … Continue reading

Posted in controls, strings | Tagged , , , , , , , , , , , , , | Leave a comment

Set tab positions inside a ListBox or TextBox in C#

This example demonstrates three methods for aligning values in columns, two of which set tab positions in a ListBox or TextBox. To set tabs in a ListBox, you need to set the control’s UseCustomTabOffsets property to true. Then get the … Continue reading

Posted in controls | Tagged , , , , , , , , , , , , | 1 Comment