Category Archives: miscellany

Find .NET libraries for namespaces in C#

Some namespaces have names that nicely match their .NET libraries. For example, the System.Drawing namespace is defined in the System.Drawing library. Unfortunately a namespace’s name doesn’t always match the name of the .NET library that defines it. For example, the … Continue reading

Posted in .NET, miscellany | Tagged , , , , , , , , | Leave a comment

Run user-entered code that modifies the program’s form in C#

The example Run user-entered code in C# shows how you can compile and execute code entered at run time. That example simply displays a message box and returns a DialogResult indicating which button the user pressed. This example shows how … Continue reading

Posted in algorithms, miscellany, programs, reflection | Tagged , , , , , , , , , , , , , , , , | Leave a comment

Tip: Make parentheses matching more visible in C#

Recently someone asked me if there was a Visual Studio add-in that highlighted parentheses, brackets, and braces so it would be easier to tell which closing parenthesis matched which opening parenthesis. It turns out that Visual Studio already has a … Continue reading

Posted in coding, miscellany, tips | Tagged , , , , , , , , | 1 Comment

Use accelerators on labels and buttons in C#

To place an accelerator on a menu item, you put an ampersand in front of the letter in the menu item’s caption that you want to be the accelerator. At run time, the caption is displayed with the accelerator letter … Continue reading

Posted in miscellany, productivity | Tagged , , , , , , , , , , , | Leave a comment

Activate another running program in C#

This is actually quite simple. First add a reference to the Microsoft.VisualBasic library. Then call Microsoft.VisualBasic.Interaction.AppActivate, passing it the title of the program that you want to activate as in the following code. using Microsoft.VisualBasic; … // Activate the program. … Continue reading

Posted in miscellany, system | Tagged , , , , , , , , , , | Leave a comment

Use System.Threading.Timer to make a countdown timer in C#

The post Make a countdown timer in C# uses a Timer control to count down the time until some deadline. This example does something similar but it uses a Timer object from the System.Threading namespace. The basic idea is similar: … Continue reading

Posted in miscellany, system | Tagged , , , , , , , , , , , , | Leave a comment

Move a window with a title that matches a pattern in C#

The example Set another application’s size and position in C# uses the FindWindow API function to find a window with a given title. Unfortunately FindWindow only finds the window if the title is an exact match. If you only know … Continue reading

Posted in API, miscellany, regular expressions, system | Tagged , , , , , , , , , , , , | Leave a comment

Tile desktop windows in rows and columns in C#

The example List desktop windows in C# shows how to list the currently running desktop windows. This example uses that technique to fill a ListBox with the titles of those desktop windows. (See the previous example to see how that … Continue reading

Posted in API, miscellany, system | Tagged , , , , , , , , , , , | Leave a comment

Set another application’s size and position in C#

When I write books, there is usually a maximum size that a screen shot can be. I wrote this program to make it easy to set an example program to exactly that size. This program uses the FindWindow API function … Continue reading

Posted in API, miscellany, system | Tagged , , , , , , , , , , , , , , , , , , , , , , , , , | 3 Comments

Find a target window and minimize, maximize, or restore it in C#

This is the first in a series of posts that allow one application to manipulate a target window in another application. Note that this isn’t something that Microsoft really wants you to do. In general one application should not fiddle … Continue reading

Posted in API, miscellany, system | Tagged , , , , , , , , , , , , , , , , , , , , , , , , , | Leave a comment