Tag Archives: example program

Display a colored battery status in C#

This is a minor update to the example Display battery status in a friendly way in C#. That example periodically checks the battery’s charge. It then draws textual and graphical indicators of the charge and plugged/unplugged status. That example was … Continue reading

Posted in drawing, graphics, system | Tagged , , , , , , , , , , | Comments Off on Display a colored battery status in C#

How to tabulate ranked voting in C#

New York City’s recent election used a ranked voting ballot. This example shows how you might find the winner in a ranked voting election. What Is Ranked Voting? In ranked voting (aka ranked-choice voting or preferential voting), each voter ranks … Continue reading

Posted in algorithms | Tagged , , , , , , | Comments Off on How to tabulate ranked voting in C#

Select rectangular areas in an image in WPF and C#

This is another fine example of WPF’s unofficial slogan: Twice as flexible and only five times as hard. Practically everything about this example is harder than it is in Windows forms: drawing the rectangle, selecting the area, saving the results … Continue reading

Posted in graphics, wpf | Tagged , , , , , , , , , , , | Comments Off on Select rectangular areas in an image in WPF and C#

Use VBA code to add and remove a watermark on all pages in a Word document

This post shows one way that you can add and remove a watermark in a Word document. To add a watermark in this way, you add a “building block” to the header of each of the document’s sections. If headers … Continue reading

Posted in Office, VBA | Tagged , , , , , , , | 1 Comment

Graph the gamma function in C#

The post Calculate the gamma function in C# uses numerical integration to calculate the gamma function. (See my book Essential Algorithms, Second Edition for information on numerical integration.) That method works fairly well for calculating Γ(x) where x ≤ 1. … Continue reading

Posted in algorithms, graphics, mathematics | Tagged , , , , , , , , | Comments Off on Graph the gamma function in C#

Calculate the gamma function in C#

The gamma function, represented by the capital Greek letter gamma Γ, was derived by Daniel Bernoulli for complex numbers with a positive real part. The interesting thing about the gamma function is that &Gamma(n + 1) = n! for integers … Continue reading

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

Find rectangles defined by a side and aspect ratio in C#

You probably haven’t needed to make your program draw rectangles that are defined by specifying one of its sides. I haven’t either, but I want this for another program that I plan to write. Of course a single side isn’t … Continue reading

Posted in drawing, geometry, graphics | Tagged , , , , , , , , , | 3 Comments

Zip files with the ZipFile class in C#

The static ZipFile class is relatively new (.NET Framework 4.5 and later), so this example uses Visual Studio 2019. The following section explains how to load the ZipFile class in a Visual Studio 2019 project. The rest of this post … Continue reading

Posted in files | Tagged , , , , , , , , , | Comments Off on Zip files with the ZipFile class in C#

Simulate a doubling betting strategy in C#

Casinos love customers who have a betting strategy because those customers always end up losing. As long as the game’s events are independent of each other (for example, one roll of the dice does not depend on the previous rolls), … Continue reading

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

Book Drawing: C++ All-in-One For Dummies, 4th Edition

John Mueller has kindly donated five copies of his book C++ All-in-One For Dummies, 4th Edition for me to give away. The only catch is that you should post a review on Amazon when you’ve had a chance to look … Continue reading

Posted in books | Tagged , , , , , , | Comments Off on Book Drawing: C++ All-in-One For Dummies, 4th Edition