Tag Archives: C# programming

Use regular expressions to rename files in a directory hierarchy in C#

This example extends the example Use regular expressions to rename files within a date range and that match a pattern in C# to let you rename files that match a pattern and that were modified within a date range. See … Continue reading

Posted in files, regular expressions | Tagged , , , , , , , , , , , , | Comments Off on Use regular expressions to rename files in a directory hierarchy in C#

Copy a C# project

Sometimes you might want to copy a C# project so you can save the current version or so you can modify it for another purpose. Unfortunately, when you copy a C# project, the copied program does not automatically update the … Continue reading

Posted in C# | Tagged , , , , , , | Comments Off on Copy a C# project

Remove all event handlers from an event in C#

I found this technique on this Microsoft forum. When you click the program’s Add button, the following code installs several event handlers. private void btnAdd_Click(object sender, EventArgs e) { btnClickMe.Click += btnClickMe_Click; picCanvas.Click += picCanvas_Click; picCanvas.MouseClick += picCanvas_MouseClick; picCanvas.MouseDown += … Continue reading

Posted in events | Tagged , , , , , , | Comments Off on Remove all event handlers from an event in C#

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 Γ(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