Category Archives: controls

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

Make TextBoxes automatically convert case in C#

It’s actually quite easy to make a TextBox convert case in .NET. Simply set the TextBox control’s CharacterCasing property to Lower or Upper. Then the control automatically converts alphabetic characters into the correct case. You can do this at design … Continue reading

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

Sort ListView controls by all columns or clicked columns in C#

The ListView control provides features to sort its values but by default it doesn’t use them. This example shows how you can add extension methods to the control to make it sort on all columns or on clicked columns. This … Continue reading

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

Display thumbnails for image files in a directory in C#

This example shows how to display thumbnails for the images in a directory. It displays a tooltip when the mouse hovers over a picture and it opens the image file in the default application if you double-click on an image. … Continue reading

Posted in controls, graphics, image processing | Tagged , , , , , , , , , , , , | Leave a comment

Display tooltips for ListView items in C#

This example shows how to display different tooltips for the items in a ListBox. When you move the mouse over an item in the ListBox, the program uses the following code to display a tooltip for it. // Display a … Continue reading

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

Override WndProc to see when the user clicks any control on a form in C#

A form’s WndProc method processes messages sent to the form by the Windows operating system. This is an extremely important method that allows forms to move, resize, repaint, and perform other critical operations. While you normally don’t need to change … Continue reading

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

Center the cursor over a particular control in C#

Some programs move the mouse to center the cursor over a particular control to make some sort of selection easier. For example, it might move the mouse over a dialog’s OK button. Personally I find that annoying as a user, … Continue reading

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

Find the word under the mouse in a RichTextBox control in C#

The following WordUnderMouse method returns the word under the mouse in a RichTextBox. // Return the word under the mouse. private string WordUnderMouse(RichTextBox rch, int x, int y) { // Get the character’s position. int pos = rch.GetCharIndexFromPosition(new Point(x, y)); … Continue reading

Posted in controls, miscellany | Tagged , , , , , , , , , , , | 2 Comments

Handle NumericUpDown value change events in C#

The post Make a NumericUpDown use decimal values in C# shows how you can make a NumericUpDown control display decimal values. When the user clicks a NumericUpDown control’s arrows or presses the up or down arrow key while the control … Continue reading

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

Make a NumericUpDown use decimal values in C#

Most developers know that the NumericUpDown control lets a user select a number, but few know that it can handle decimal values in addition to integers. The control’s DecimalPlaces property determines the number of digits after the decimal that the … Continue reading

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