Close All Forms in an Application in a Thread-Safe Manner

26 Comments »

Closing all forms in an application seems like it would be a simple task of using a foreach loop in the Application.OpenForms collection, such as:

foreach (Form form in Application.OpenForms)
{
    form.Close();
}

But there are two problems.

Read the rest of this entry »

C# Read String Line by Line

4 Comments »

It’s easy to read a string one line at a time.  Here is a console program that demonstrates how:

Read the rest of this entry »

C# Convert String to Stream, and Stream to String

27 Comments »

It’s fairly easy to convert a C# String to a Stream and vice-versa.

Read the rest of this entry »

Show ToolTip on TabPage in TabControl

3 Comments »

So you’ve set the ToolTipText property of a TabPage in a TabControl.  When the user moves the mouse pointer over the tab, the text you specified is supposed to show in a tooltip. 

TabPage ToolTip

But what if the tooltip is not showing?  Fortunately, this problem has an easy solution:

Set the ShowToolTips property in the TabControl to true.

Clear C# StringBuilder

8 Comments »

Many .NET developers are baffled by the lack of a “Clear” method in the StringBuilder class.  For example, if you are using a StringBuilder in a loop, you may want to clear its contents at the beginning of each loop.

Read the rest of this entry »

Determine Windows Version and Edition with C#

19 Comments »

This article explains how to use C# to determine the name, edition, service pack, version and bits of the host operating system.

For example, the results on my PC would be:

Operation System Information
—————————-
Name = Windows Vista
Edition = Home Premium
Service Pack = Service Pack 1
Version = 6.0.6001.65536
Bits = 64

Read the rest of this entry »