Author Archives: Rod Stephens

Use anonymous methods in C#

My previous post Use the predefined Action, Func, and EventHandler delegate types in C# explains how to use the predefined generic Func, Action, and EventHandler delegate types to graph four functions F(x, y). It uses the following code to define … Continue reading

Posted in algorithms, graphics, variables | Tagged , , , , , , , , , , , , | 1 Comment

Use the predefined Action, Func, and EventHandler delegate types in C#

This and the next couple of posts discuss delegates and the somewhat related topics of anonymous methods and lambda expressions. Briefly, delegate types are programmer-defined data types that represent methods. For example, the following code declares a delegate type. // … Continue reading

Posted in algorithms, graphics, variables | Tagged , , , , , , , , , , , , | 1 Comment

A quick note on error messages

I went to a local museum the other day 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 … Continue reading

Posted in MessageBox, miscellany, user interface | Tagged , , , , , , , , , , , , , | 1 Comment

Make a button display the picture beneath it in C#

This example makes a button display copies of the picture on which it sits, making it appear that the button is part of the underlying image. The key to this example is the following SetButtonBackground method. // Make the Button … Continue reading

Posted in controls, graphics, image processing | Tagged , , , , , , , , , , , , | 1 Comment

Validate optional parameters in C#

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

Posted in methods, syntax, variables | Tagged , , , , , , , , , , , , , | 1 Comment

Use named and optional parameters in C#

Optional parameters is one of the few additions in recent versions of Visual Studio that are really useful. I usually try to post examples in an older version of C# because it’s easier for someone to move an older example … Continue reading

Posted in methods, syntax, variables | Tagged , , , , , , , , , , , , , | 1 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 | Tagged , , , , , , , , , , , , , , | Leave a comment

Get system metrics in C#

The GetSystemMetrics API function returns system metrics, values that give dimensions used by the system such as the default size of icons and the thickness of a resizable window’s borders. For example, the highlighted line in the picture on the … Continue reading

Posted in API, system | Tagged , , , , , , , , , , , , | 1 Comment

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 arrays of bytes. (I suppose it might have made more sense to call it the ByteConverter class.) You can use those methods to convert … Continue reading

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

Make subarray extension methods in C#

The Array class’s Copy method can copy a subarray 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 … Continue reading

Posted in arrays, extension methods | Tagged , , , , , , , , , | Leave a comment