Monthly Archives: March 2017

Parse file sizes in KB, MB, GB, and so forth in C#

The example Format file sizes in KB, MB, GB, and so forth in C# shows how to convert a number into a string formatted in KB, MB, etc. This example does the opposite: it parses a value such as “1.23 … Continue reading

Posted in algorithms, files, mathematics | Tagged , , , , , , , , , | Leave a comment

Highlight the DataGridView row that is under the mouse in C#

Someone recently asked me how to change the style of the row under the mouse in a DataGridView control. This example does that. When the program starts, the following code prepares the DataGridView for use. // The style to use … Continue reading

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

Use accelerators on labels and buttons in C#

To place an accelerator on a menu item, you put an ampersand in front of the letter in the menu item’s caption that you want to be the accelerator. At run time, the caption is displayed with the accelerator letter … Continue reading

Posted in miscellany, productivity | Tagged , , , , , , , , , , , | Leave a comment

Compare the performance of incrementing statements in C#

This is another performance testing post. Assembly language usually has statements comparable to x++, x–, x +=, and other operators that add or subtract to a value and store the result in the same value, so it makes some sense … Continue reading

Posted in performance, syntax | Tagged , , , , , , , , , | Leave a comment

Make a simple event logger in C#

Usually the debugger lets you examine how a program works quite effectively, but sometimes it’s useful to use an event logger to record events for later study. For example, when you’re working with mouse events, stopping execution at a break … Continue reading

Posted in classes, debugging, files | Tagged , , , , , , , , , , | Leave a comment

Display a form’s control hierarchy in C#

This example displays the control hierarchy for a form. It’s actually relatively simple. Some controls can contain other controls. For example, a form is a control and it contains all of a Windows Forms application’s controls. Similarly Panel, TableLayoutPanel, SplitContainer, … Continue reading

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

Loop over a form’s controls in C#

This example shows how to loop over controls of various types on a form. The Control class defines a Controls property that is a collection containing references to the controls inside a control. For example, a form’s Controls collection holds … Continue reading

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

Make a shaded ellipse control in C#

Note: Before you can use the ShadedEllipse control in the example program, you must build the solution. After you download the example, build it before you try to view the form. This example walks through building a control that draws … Continue reading

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

Quickly insert standard menu items on a form in C#

Many applications need standard File, Edit, Tools, and Help menus. Visual Studio provides a simple way to build standard menu items. You can then edit the menu to add new items and remove items that you don’t need. Visual Studio … Continue reading

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

Give a class default indexer properties in C#

An indexer property is a property that other code can use inside square brackets to access some value provided by the class, much as you can use the index of an array. Unlike an array, a class’s indexer need not … Continue reading

Posted in arrays, classes, syntax | Tagged , , , , , , , , , | Leave a comment