Monthly Archives: October 2013

Make a C# DLL and use it from Excel VBA code

This example shows how to make a C# DLL and then use it from VBA code running in Excel. A similar procedure should work for other Office applications. Note that some of the steps may require modification and significant fiddling … Continue reading

Posted in Excel, interoperability, Office, VBA | 8 Comments

Display pictures taken from a database at runtime in a ListView control in C#

My previous post, Generate pictures for ListView items at run time in C#, explained how to make images at runtime to display in a ListView control. This example follows from that one. Simply get the images you want from the … Continue reading

Posted in controls | 7 Comments

Generate pictures for ListView items at run time in C#

The example Make a ListView control display large and small icons in C# explains how to make a ListView control display images next to its items. Basically you place the images in two ImageList controls, set the ListView control’s LargeImageList … Continue reading

Posted in controls | Leave a comment

Use LINQ with an embedded lambda expression to find prime numbers in C# (Part 3 of 3)

(This example is in Visual Studio 2012.) The example Use more efficient LINQ to find prime numbers in C# (Part 2 of 3) uses a LINQ query to find prime numbers. It creates a delegate variable named IsOddPrime referring to … Continue reading

Posted in LINQ, mathematics | Leave a comment

Use more efficient LINQ to find prime numbers in C# (Part 2 of 3)

(This example is in Visual Studio 2012.) The previous post showed how you can use LINQ to find prime numbers. For every numbers between 1 and a maximum, the LINQ query called the IsPrime method to see if the number … Continue reading

Posted in LINQ, mathematics | Leave a comment

Use LINQ to find prime numbers in C# (Part 1 of 3)

(This example is in Visual Studio 2012.) This program defines the following IsPrime method to determine whether a number is prime. // Return true if the number is prime. private bool IsPrime(int number) { if (number < 2) return false; … Continue reading

Posted in LINQ, mathematics | Leave a comment

Draw a cursor and use it at run time in C#

The basic approach is to create a Bitmap and then create a new Cursor object, passing its constructor the Bitmap’s icon handle as given by its GetHicon method. When the example starts, it uses the following code to create a … Continue reading

Posted in drawing, graphics | Leave a comment

Let the user select a scroll bar’s largest value in C#

The behavior of the VScrollBar and HScrollBar controls is largely determined by their Value, Minimum, Maximum, SmallChange, and LargeChange properties. Value – The control’s current value Minimum – The smallest value the control can have Maximum – The smallest value … Continue reading

Posted in controls | Leave a comment

Handle a problem with smoothing mode when filling a rectangle in C#

If you look closely at the PictureBox on the right in the picture, you’ll see that its top and leftmost pixels are not the same color as the rest of the PictureBox. The same thing was happening in a program … Continue reading

Posted in drawing, graphics | Leave a comment

Use the ZipFile class to compress and decompress directories in C#

The ZipFile class provides remarkably simple methods for compressing and decompressing directories in zip format. This class is defined in the .NET Framework version 4.5 so this example is in Visual Studio 2012 instead of an older version. To use … Continue reading

Posted in classes, directories, files | Leave a comment