Monthly Archives: February 2013

Change the form’s AcceptButton depending on which control has focus in C#

You’ve probably seen applications, often on web sites, where the action that a form takes when you press Enter depends on the control that has focus at the time. For example, many log in pages have a place for you … Continue reading

Posted in controls | Leave a comment

Initialize a TreeView control to display a directory hierarchy in C#

This example adds the following LoadFromDirectory extension method to the TreeView class. // Initialize the TreeView from a directory, // its subdirectories, and their files. public static void LoadFromDirectory(this TreeView trv, string directory, int folder_img, int file_img) { DirectoryInfo dir_info … Continue reading

Posted in controls, directories, files | Leave a comment

Cast arrays from one reference type to another in C#

Every C# programmer knows that you can use a cast operator to convert one data type into another. For example, if the Employee class inherits from the Person class, then the following code creates an Employee object and then makes … Continue reading

Posted in arrays, syntax, variables | Leave a comment

Make a form remain on top of or below other windows in C#

Keeping a form on top of other windows is simple. Just set the form’s TopMost property to true. Keeping a form below other windows is harder. To do that, the program must override its WndProc method, look for messages that … Continue reading

Posted in API, controls, forms | Leave a comment