Tag Archives: C#

Unblock files received from email or the internet in C#

I do a lot of technical editing. When a project editor sends me files, Windows marks them as from an “untrusted” source. Then when I try to open the files in Word, it warns me and asks if I want … Continue reading

Posted in extension methods, files | Tagged , , , , , , , , , , , | Comments Off on Unblock files received from email or the internet in C#

Find palindrome dates in C#

A palindrome date is a date that, in numeric format, reads the same forward and backward. For example, 12/1/21. To find the most dates, you can consider any formats including two-digit days and four-digit years, and you can ignore the … Continue reading

Posted in games, strings | Tagged , , , , , , , , , | Comments Off on Find palindrome dates in C#

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#