Category Archives: algorithms

Draw a scrolling family tree in C#

The example Draw a family tree in C# shows how to draw a family tree. Unfortunately if the tree is too big, you can’t make the form big enough to display it all. One solution would be to use smaller … Continue reading

Posted in algorithms, classes, generic, graphics, OOP | Tagged , , , , , , , , , , , , , , , , , , , , , | 1 Comment

Use “banker’s rounding” and “normal rounding” in C#

By default the Math.Round method uses “banker’s rounding.” In banker’s rounding a number with a final digit of 5 is rounded to the nearest even number rather than to the next larger number as you might expect. The idea is … Continue reading

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

Make a cannon game in C#

This simple cannon game randomly positions a target house. Then when you click the Shoot button, it gets angle and speed information for the cannon and enables a timer. To keep the graphics and timing simple, the program uses a … Continue reading

Posted in algorithms, animation, games, graphics | Tagged , , , , , , , , , , , , , | Leave a comment

Extract text from a metafile in C#

The example Enumerate the records in a metafile in C# shows how to list the records in a metafile. This example lists the records, looks for those that represent DrawString commands, and extracts their text. The following code shows the … Continue reading

Posted in algorithms, graphics | Tagged , , , , , , , , , , , | 2 Comments

Enumerate the records in a metafile in C#

The example Display a Windows metafile (wmf) in C# shows how to draw a metafile. This example shows how to enumerate the records in the metafile that represent its drawing commands and draw only some of them. When you enter … Continue reading

Posted in algorithms, graphics | Tagged , , , , , , , , , | Leave a comment

Draw an interesting pattern of circles in C#

This program simply draws an interesting arrangement of circles. I wrote it because a C# Helper post was mentioned on this Factal [sic] Patterns & Art page. This program uses the following code to draw the circles and connecting lines. … Continue reading

Posted in algorithms, drawings, geometry, graphics, mathematics | Tagged , , , , , , , , , , , , | Leave a comment

Use BeginInvoke and callbacks to perform tasks asynchronously in C#

The example Use BeginInvoke and EndInvoke to perform tasks asynchronously in C# explains one way to call a method asynchronously so it can run on a separate core or CPU. In that example, the program calls BeginInvoke several times to … Continue reading

Posted in algorithms, graphics, image processing, threading | Tagged , , , , , , , , , , , , , , , , | Leave a comment

Use BeginInvoke and EndInvoke to perform tasks asynchronously in C#

This example uses the Emboss method to create embossed images. How that method works isn’t important to the discussion of working asynchronously so it isn’t covered here. Download the example to see how it works. The only thing about that … Continue reading

Posted in algorithms, graphics, image processing, threading | Tagged , , , , , , , , , , , , , | Leave a comment

Loop over an array of unknown dimension in C#

The previous post Loop over entries in an array of unknown length in C# explains how to loop over the entries in a one- or two-dimensional array, but what do you do if you don’t know how many dimensions an … Continue reading

Posted in algorithms, arrays, recursion, variables | Tagged , , , , , , , , , , , , , , , , | 1 Comment

Add “extension properties” to classes in C#

Extension methods allow you to add new methods to existing classes even if you don’t have access to the classes’ source code. For example, the Randomize two-dimensional arrays in C# example shows how to add an extension method to two-dimensional … Continue reading

Posted in algorithms, classes, extension methods | Tagged , , , , , , , , , | 1 Comment