Monthly Archives: September 2017

Draw a picture-filled histogram in C#

The example Make a simple histogram in C# shows how to draw a histogram. This example shows how to fill the histogram’s bars with pictures. The following TileRectangle method fills a rectangle with an image. // Tile an area from … Continue reading

Posted in drawing, graphics, mathematics | Tagged , , , , , , , , , , , , | Leave a comment

Write values in the Registry in C#

The example Read Registry values (to get the desktop icon size) in C# shows how to read values from the Registry. This example shows how to write values into the Registry and uses that ability to refresh the desktop icons … Continue reading

Posted in registry, system | Tagged , , , , , , , , , , | Leave a comment

Read Registry values (to get the desktop icon size) in C#

To make using Registry methods easier, this example defines a RegistryTools class that contains static methods for interacting with the Registry. The following code shows the GetRegistryValue method. // Get a registry value. public static object GetRegistryValue(RegistryKey hive, string subkey_name, … Continue reading

Posted in registry, system | 3 Comments

Linkback to the Secret Santa Problem

Tom left a comment to my post Calculate the number of secret Santa permutations in C#. He used that example to build a site in JavaScript explaining how the algorithm works. It’s a pretty cool little page. Drop by and … Continue reading

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

Define custom exception classes in C#

The example Throw a standard exception in C# explains how to throw exceptions to tell the program about unexpected errors. The example See a hierarchy of exception classes for use in C# lists some useful exception classes. But what if … Continue reading

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

See a hierarchy of exception classes for use in C#

The example Throw a standard exception in C# explains how to throw exceptions to indicate a problem in a program. Throwing an exception is easiest if you can find an existing exception class that correctly represents your situation. The following … Continue reading

Posted in coding | Tagged , , , , , , , , , , , | 2 Comments

Throw standard exceptions in C#

The example Use try catch blocks to protect against unexpected errors in C# explains how to catch an exception and briefly mentions that you can use the throw statement to throw your own exception. This example shows how to throw … Continue reading

Posted in coding | Tagged , , , , , , , , , , , | 2 Comments

Make a dice-rolling simulation in C#

This example performs a simulation of rolling two six-sided dice. It’s related to my book Interview Puzzles Dissected, which includes several examples that involve rolling dice. When you enter a number of trials and click Roll, the program uses the … Continue reading

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

Tile a PictureBox in C#

If you set a form’s BackgroundImageLayout property Tile, then the control fills itself with copies of its background image. Strangely the PictureBox control does not have a corresponding Tile property. This example shows one way you can tile images on … Continue reading

Posted in drawing, graphics, image processing | Tagged , , , , , , , , , , , , | Leave a comment

Use a symbiote to graphically select hours in C#

This example modifies the previous example Graphically select hours in C# so it uses a symbiote class. That example shows how to use a PictureBox to let the user select a range of hours. If you want to let the … Continue reading

Posted in controls, graphics, user interface | Tagged , , , , , , , , , , , , | 1 Comment