Author Archives: Rod Stephens

Convert a Rectangle into a RectangleF and vice versa in C#

The RectangleF structure has an overloaded assignment operator = that lets you simply set a RectangleF equal to a Rectangle, so converting a Rectangle into a RectangleF is easy. That makes sense because converting from Rectangle to RectangleF is a … Continue reading

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

Make a hangman game in C#

Special thanks to Jeff Scarterfield for the skeleton drawing used by the program. This example builds a simple hangman game that uses the dictionary created by the example Use LINQ to select words of certain lengths from a file in … Continue reading

Posted in algorithms, files, games, graphics, strings | Tagged , , , , , , , , , , , , | Leave a comment

Use LINQ to select words of certain lengths from a file in C#

This example uses LINQ to read a file, remove unwanted characters, select words of a specified length, and save the result in a new file. Recently I needed a big word list so I searched around for public domain dictionaries. … Continue reading

Posted in algorithms, files, LINQ | Tagged , , , , , , , , , , , | 2 Comments

Draw a golden spiral in C#

This example shows how to draw a golden spiral (or phi spiral) in C#. The example Draw a nested series of golden rectangles in C# draws nested rectangles and connects their corners to make a square “spiral.” This example makes … Continue reading

Posted in algorithms, drawing, graphics, mathematics | Tagged , , , , , , , , , , , , , , | 3 Comments

Draw a nested series of golden rectangles in C#

This program draws golden rectangles, rectangles whose side ratio is equal to φ. For information on φ, see Examine the relationship between the Fibonacci sequence and phi in C#. The program first draws a golden rectangle. It then removes the … Continue reading

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

Examine the relationship between the Fibonacci sequence and phi in C#

The golden ratio (also called the golden mean, golden section, or divine proportion) is a number that pops up in a surprising number of places in geometry and nature. This number is also called φ (phi, pronounced either “fee” or … Continue reading

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

Use a TextFieldParser to read fixed-width data in C#

This example uses a TextFieldParser object to load fixed-width data from a file that contains names and addresses. Each field has a fixed width. Some records also have ZIP+4 format ZIP codes (for example, 08109-2120) and the program should discard … Continue reading

Posted in classes, database, files, parsing | Tagged , , , , , , , , , , , , , , , | Leave a comment

Use a TextFieldParser to read delimited data in C#

This example uses a TextFieldParser object to parse a data file that contains name and address data. The data contains fields delimited by commas and semi-colons. Some records also have ZIP+4 format ZIP codes (for example, 08109-2120) and the program … Continue reading

Posted in classes, database, files, parsing | Tagged , , , , , , , , , , , , , | 2 Comments

Suspend or hibernate the system in C#

The Application.SetSuspendState method lets an application make the system suspend or hibernate. A suspended system enters a low power mode. A hibernating system saves its memory contents to disk and then enters low power mode. Because it doesn’t need to … Continue reading

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

Explore the Visual Studio Image Library in C#

This example explains where you can find standard images in the Visual Studio Image Library that you can use in your applications. The example Give transparent backgrounds to images displayed on buttons in C# explains how to make some pixels … Continue reading

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