C# WinForms Form Event Order

1 Comment »

Sometimes it’s important to understand the order of events that occur when a WinForms Form is opened, closed, shown or hidden.  There are also a few “gotchas” that are important to know.

Read the rest of this entry »

Popularity: 24% [?]

The Proper Way to Show the Wait Cursor

9 Comments »

It’s common UI courtesy to show the Wait cursor when performing a long operation that requires the user to wait.  Here is how the Wait cursor appears in Windows Vista:

Wait cursor

But developers often go about this the wrong way by setting the Cursor.Current property as follows:

Cursor.Current = Cursors.WaitCursor;

Read the rest of this entry »

Popularity: 25% [?]

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

8 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 »

Popularity: 32% [?]

Show ToolTip on TabPage in TabControl

No 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.

Popularity: 19% [?]

DataGridView HideSelection to Hide Selection when Grid Loses Focus

No Comments »

The DataGridView is a powerful grid control included in the .NET Framework.  One function missing, however, is the ability to hide the current selection when the DataGridView control is not focused.  What the DataGridView class needs is a HideSelection property, similar to the ListView and TextBox.  But the .NET designers have not included this capability in the DataGridView class.

Read the rest of this entry »

Popularity: 26% [?]

Add Shaded Rows to ListView Details View

8 Comments »

Sometimes it can be challenging to read the Details view in a ListView, especially if the rows are long.  This article shows how to add shading to every second row to make a ListView easier to read.

ListView Shaded Rows

Read the rest of this entry »

Popularity: 35% [?]

Show Continuous Progress with .NET ProgressBar and MarqueeAnimationSpeed

12 Comments »

For some operations such as logging on to a web site or downloading a web page, you may not know how long it will take the operation to finish.  So instead of showing a progress bar with a specified percent complete, you can set the .NET ProgressBar to cycle continuously.

ProgressBarMarquee

Read the rest of this entry »

Popularity: 41% [?]

Manipulating Controls Across Threads

5 Comments »

Methods that affect a Windows Forms control can be executed only on the thread that created the control. .NET does not permit directly manipulating controls across threads. The Visual Studio compiler under .NET 2.0 will mark these attempts as errors. .NET 1.1 will allow them, but these will often result in unexpected behavior like incorrectly-painted controls.

Read the rest of this entry »

Popularity: 39% [?]

Convert Handle to Form, and Vice Versa

No Comments »

This is one of those things that's obvious once you know it.  When dealing with COM, there is often a need to convert a WinForms Form object to an IntPtr handle, and vice versa.

Read the rest of this entry »

Popularity: 28% [?]

NotifyIcon.ShowBalloonTip Issues

8 Comments »

NotifyIcon is .NET's version of the system tray icon, those little icons that appear next to the clock in the Windows Start bar.  .NET 2.0 added the ability to display a pop-up balloon tip pointing at a tray icon.  However, this capability doesn't always work as you would expect.

Read the rest of this entry »

Popularity: 42% [?]

keep looking »