Monthly Archives: December 2012

A quick note on error messages

I went to a local museum yesterday and when the attendant scanned by membership card his computer said: Object not set to a reference of an object. Because we’re programmers, you and I know what that means (more or less), … Continue reading

Posted in MessageBox, miscellany | 1 Comment

Make a button display the picture that is under it in C#

(Sorry for the holiday season slowdown. I won’t be able to post as much for a little while yet.) This example makes buttons display copies of the picture on which they sit, making it appear that the button is part … Continue reading

Posted in controls, graphics | Leave a comment

Validate optional arguments in C#

The example Use named and optional arguments in C# explains how to use named and optional arguments to let the calling code omit any combination of optional arguments. In many applications, you may not want to allow the user to … Continue reading

Posted in methods, syntax, variables | 1 Comment

Use named and optional arguments in C#

Usually I try to post examples in an older version of C# because it’s easier for someone to move an older example to a more recent version than it is to move a recent example to an older version. Most … Continue reading

Posted in methods, syntax, variables | Leave a comment

Display system metric values with descriptions in C#

The example Get system metrics in C# shows how to get system metrics but the the metrics’ terse names make the results hard to understand. This example displays descriptions of the metrics in addition to their values. Some of the … Continue reading

Posted in API, system | Leave a comment

Get system metrics in C#

The GetSystemMetrics API function returns values that give dimensions used by the system such as the default size of icons and the thickness of a resizable window’s borders. The following code shows how the program declares the GetSystemMetrics API function. … Continue reading

Posted in API, system | Leave a comment

Use the BitConverter class to convert an array of bytes into an integer and back in C#

The BitConverter class provides static methods that let you convert various data types to and from byte arrays. (I suppose it might have made more sense to call it the ByteConverter class.) You can use those methods to convert data … Continue reading

Posted in classes | Leave a comment

Make SubArray extension methods that let you easily copy parts of one- and two-dimensional arrays in C#

The Array class’s Copy method can copy items from one array to another but it requires that you figure out how many items you want to copy. It will also copy parts of a two-dimensional array but it only copies … Continue reading

Posted in arrays, extension methods | Leave a comment

Visual Studio 2012 Image Library is available for download

The Visual Studio 2012 Modern Image Library includes more than 5,000 icons, bitmaps, and other images that you can use in your applications. These are the images used by Microsoft applications so using them can make your application look more … Continue reading

Posted in graphics | Leave a comment

Use the Array.Copy method to copy values in two-dimensional arrays in C#

The Array.Copy method can copy values from one array to another. For one-dimensional arrays, this is reasonably straightforward. You specify the source and destination arrays, the indices where copying should start in the two arrays, and the number of items … Continue reading

Posted in arrays | Leave a comment