Monthly Archives: June 2015

Find Egyptian fractions in C#

An Egyptian fraction is a fraction expressed as a sum of distinct unit fractions. For example, you can write 3/7 as 1/3 + 1/11 + 1/231. You can write any fraction as an Egyptian fraction and there may be more … Continue reading

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

Make a Fraction class in C#

The Fraction class represent rational numbers using fractions, at least until the numerators and demoninators get too big. The Fraction class uses the following code, most of which is straightforward. class Fraction { public long Numerator, Denominator; // Initialize the … Continue reading

Posted in algorithms, classes, mathematics | Tagged , , , , , , , , , , , , , , , | 1 Comment

Find shortest paths in a network C#

This example shows one method for finding shortest paths in a network such as a street, telephone, or computer network. It’s a fairly advanced example adapted from my book Essential Algorithms: A Practical Approach to Computer Algorithms. See the book … Continue reading

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

Use a control array in C#

Sometimes it may be handy to use a control array. Way back before .NET, Visual Basic let you define control arrays at design time. The concept disappeared in .NET, but they can still be useful if you need to perform … Continue reading

Posted in arrays, classes, syntax | Tagged , , , , , , , , , | 3 Comments

Prevent Visual Studio from running programs with syntax errors

If a program’s code contains syntax errors, then by default if you try to run the program Visual Studio displays the following message: You should pretty much always click No. If you click Yes, an older version of the program … Continue reading

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

Zoom and crop a picture in C#

This program lets the user zoom in and then click and drag to crop a picture. When you zoom in, the selection rectangle snaps to positions between the image’s enlarged pixels so it’s easy to tell exactly which pixels are … Continue reading

Posted in graphics, image processing | Tagged , , , , , , , , , , , | 2 Comments

Use PixelOffsetMode in C#

This example lets you see how different PixelOffsetMode values work when you enlarge an image. When you resize an image, the graphics method examines the pixels in the result image. It maps each output pixel back to a position in … Continue reading

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

Crop a picture in C#

The program uses three Bitmap objects to hold different copies of the current image. // The original image. private Bitmap OriginalImage; // The currently cropped image. private Bitmap CroppedImage; // The cropped image with the selection rectangle. private Bitmap DisplayImage; … Continue reading

Posted in graphics, image processing | Tagged , , , , , , , , , , , | 17 Comments

Get and set file times in C#

The File class provides methods that get and set file times including the creation, modification, and access times. The following code shows how the example uses those methods to get and set a file’s times. // Get the file’s times. … Continue reading

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

Create a Visual Studio toolbar button

The example Create a Visual Studio tool shows how to add useful web or email capabilities to Visual Studio’s Tools menu. This entry explains how to add a Visual Studio toolbar button for those commands so they’re easier to use. … Continue reading

Posted in IDE, miscellany | Tagged , , , , , , , , , , , , , , | 1 Comment