Monthly Archives: December 2014

Size forms to fit their contents in C#

This example shows how to size forms to fit their contents. Figuring out how to size forms can be tricky, particularly if a form contains a MenuStrip with LayoutStyle = Flow so the MenuStrip may hold more than one row … Continue reading

Posted in controls, forms | Tagged , , , , , , , , , | Comments Off on Size forms to fit their contents in C#

Draw a Bezier curve by hand in C#

The example Draw a Bezier curve in C# shows how to use the Graphics class’s DrawBezier method to draw a Bezier curve. This post explains the equations that draw a Bezier curve and shows how you can use them to … Continue reading

Posted in algorithms, drawing, geometry, graphics, mathematics | Tagged , , , , , , , , , , , | 2 Comments

Draw a Bezier curve in C#

This example shows how to use the Graphics class’s DrawBezier method to draw a Bezier curve. A Bezier curve connects two end points with a smooth curve. The shape of the curve is determined by two control points. The control … Continue reading

Posted in algorithms, drawing, geometry, graphics | Tagged , , , , , , , , , , | 1 Comment

Find, open, and replace text in files in C#

The example Find files and replace text in them in C# shows how you can find and replace text in files. This example modifies that one to let you open the files you find by double clicking on them in … Continue reading

Posted in directories, files, tools | Tagged , , , , , , , , , , , , , | Comments Off on Find, open, and replace text in files in C#

Find files and replace text in them in C#

This program lets you recursively find files in a directory hierarchy that match one or more patterns. You can then replace text in those files with new text. Both the Find and Find & Replace buttons call the SearchForFiles method. … Continue reading

Posted in directories, files, tools | Tagged , , , , , , , , , , , | 1 Comment

Improve the jigsaw puzzle program in C#

The original jigsaw puzzle program works pretty well, but it takes a little while when you click on a tile and there are a large number of tiles. In that situation, the program spends a second or so building the … Continue reading

Posted in algorithms, games, graphics, image processing | Tagged , , , , , , , , , , , , | Comments Off on Improve the jigsaw puzzle program in C#

Make a jigsaw puzzle in C#

This example is a game sort of like a jigsaw puzzle. You load a picture, which the program breaks into tiles. You need to put the tiles in their proper positions to rebuild the image. The program draws a grid … Continue reading

Posted in algorithms, games, graphics, image processing | Tagged , , , , , , , , , , , , | 1 Comment

Send secret Santa emails in C#

This example shows how you can automatically send secret Santa emails for a party. The example Pick a secret Santa assignment in C# shows how you can quickly make secret Santa assignments. The post Calculate the number of secret Santa … Continue reading

Posted in algorithms, combinatorics, mathematics | Tagged , , , , , , , , , , , , , | Comments Off on Send secret Santa emails in C#

Calculate the number of secret Santa permutations in C#

The example Pick a secret Santa assignment in C# picks a valid permutation of the people so no one is mapped to himself or herself. Such a permutation is called a derangement. See that example for details. The number of … Continue reading

Posted in algorithms, combinatorics, mathematics | Tagged , , , , , , , , , , , , | 4 Comments

Pick a secret Santa assignment in C#

In a secret Santa party, you put everyone’s names in a hat and people draw from the hat. Each person becomes the secret Santa for the person he draws and gets that person a present for the party. To keep … Continue reading

Posted in algorithms, combinatorics, mathematics | Tagged , , , , , , , , , , , | 2 Comments