bright, fresh software
Downloads  |  Buy

Wyatt Says...

There are many Windows 7 controls already out there. I’ve included the best open source .NET components available. If you have other great controls, add them to the comments.

For each control I’ll list what versions of .NET it compiles for and what versions of Windows it will run on.

Windows Ribbon for Windows Forms

Arik Poznanski has a great series of posts about the ribbon control he wrote that wraps the Windows 7 API.

Download it now – full source code & examples. Also, view his series of articles (9 of them as of today).
Works with: Windows Forms (.NET 2.0, .NET 3.0, .NET 3.5)
Windows Versions: Only Windows 7

Windows API Code Pack for Microsoft .NET Framework

This is a mammoth control collection that is the work of 3 people.

Here are the major features:

  • Windows 7 Taskbar Jump Lists, Icon Overlay, Progress Bar, Tabbed Thumbnails, and Thumbnail Toolbars.
  • Windows 7 Libraries, Known Folders, non-file system containers.
  • Windows Shell Search API support, a hierarchy of Shell Namespace entities, and Drag and Drop functionality for Shell Objects.
  • Explorer Browser Control.
  • Shell property system.
  • Windows Vista and Windows 7 Common File Dialogs, including custom controls.
  • Windows Vista and Windows 7 Task Dialogs.
  • Direct3D 11.0, Direct3D 10.1/10.0, DXGI 1.0/1.1, Direct2D 1.0, DirectWrite, Windows Imaging Component (WIC) APIs. (DirectWrite and WIC have partial support)
  • Sensor Platform APIs
  • Extended Linguistic Services APIs
  • Power Management APIs
  • Application Restart and Recovery APIs
  • Network List Manager APIs
  • Command Link control and System defined Shell icons.

Download it now – full source code & examples.
Compiles with: Windows Forms (.NET 3.5) & Windows Presentation Foundation (WPF)
Windows Versions: Windows Vista & Windows 7

Windows 7 Progress Bar

Windows 7 Progress Bar is an open source progress bar component that allows you to add a progress bar to your program’s taskbar button. In addition, you can control the different states of the progress bar (normal, error, and paused) for Vista & Windows 7.

Download it now – full source code & examples.
Compiles with: Windows Forms (.NET 2.0, .NET 3.0, .NET 3.5)
Windows Versions: Windows 98, Windows 2000, Windows XP, Windows Vista, Windows 7

VistaMenu

VistaMenu is a menu component that allows you to add Windows 7 and Windows Vista-style menus with icons to your program. It’s written in C# and works with all .NET languages.

Download it now – full source code & examples.
Compiles with: Windows Forms (.NET 2.0, .NET 3.0, .NET 3.5)
Windows Versions: Windows 98, Windows 2000, Windows XP, Windows Vista, Windows 7

SplitButton

SplitButton is a button control with a region that shows a context menu when clicked. It’s written in C# and works with all .NET languages.

Download it now – full source code & examples.
Compiles with: Windows Forms (.NET 2.0, .NET 3.0, .NET 3.5)
Windows Versions: Windows 98, Windows 2000, Windows XP, Windows Vista, Windows 7

LinkLabel2

LinkLabel2 is a fixed version of the Windows.Forms LinkLabel control. It features the correct system “hand” cursor, and correct font rendering.

Download it now – full source code & examples.
Compiles with: Windows Forms (.NET 2.0, .NET 3.0, .NET 3.5)
Windows Versions: Windows 98, Windows 2000, Windows XP, Windows Vista, Windows 7

7 Days of Windows 7

Join me tomorrow when I talk about Finishing touches: Make your .NET app shine with professionalism. See the full list of articles in the series.

One of the great things about Vista and Windows 7 is the user isolation. Even admin users need to “elevate” their account to make system changes. Take this Date and Time dialog from Windows 7 as an example:

Every user can view the Date and time, but only administrators can change it.

Adding this ability to your .NET application

Although this series of articles is called “7 days of Windows 7” this particular article is applicable to Windows 2000 – Windows 7.

Step 1. Do we have permission?

The first step is to check if we can write to system registry or system files & folders. There are many ways to do this, but the easiest method is a simple Windows API call:

// check if user is an admin for Windows 2000 and above
[DllImport("shell32.dll", EntryPoint = "#680", CharSet = CharSet.Unicode)]
public static extern bool IsUserAnAdmin();

This will return false if you’re a limited user on Windows 2000 – Windows 7, and will also return false if you are an admin but aren’t elevated on Windows Vista and Windows 7.

In other words, it will return false if you don’t have permission to access system files & registry. And ‘ IsUserAnAdmin” returns true if you do have permission.

Step 2. Notifying the user that elevation will happen: UAC Shield Icon

To set the shield icon to one of your buttons you have to do a few things. First, set the FlatStyle of your button to “System”:

Next, you need to define a couple of functions:

public static bool AtLeastVista()
{
    return (Environment.OSVersion.Platform == PlatformID.Win32NT && Environment.OSVersion.Version.Major >= 6);
}

[DllImport("user32.dll", CharSet = CharSet.Unicode)]
public static extern IntPtr SendMessage(HandleRef hWnd, UInt32 Msg, IntPtr wParam, IntPtr lParam);

public static void SetButtonShield(Button btn, bool showShield)
{
    //Note: make sure the button FlatStyle = FlatStyle.System
    // BCM_SETSHIELD = 0x0000160C
    SendMessage(new HandleRef(btn, btn.Handle), 0x160C, IntPtr.Zero, showShield ? new IntPtr(1) : IntPtr.Zero);
}

Now, simply use this snippet in your code:

…
// UAC Shield on next button for Windows Vista+
if (AtLeastVista())
    SetButtonShield(btnName, true);
…

Step 3. Re-launching process with administrator privileges

All we have to do now is show the elevation dialog and elevate the current program. You might want to specify some arguments, but the barebones of it is as follows:

ProcessStartInfo psi = new ProcessStartInfo
                           {
                               Arguments = "-justelevated",
                               ErrorDialog = true,

                               // Handle is the handle for your form
                               ErrorDialogParentHandle = Handle,
                               FileName = Application.ExecutablePath,
                               Verb = "runas"
                           };
try
{
    Process.Start(psi);
    Close();
}
catch (Exception ex)
{
    // the process couldn't be started. This happens for 1 of 3 reasons:

    // 1. The user cancelled the UAC box
    // 2. The limited user tried to elevate to an Admin that has a blank password
    // 3. The limited user tries to elevate as a Guest account
    MessageBox.Show(ex.Message);
}

Step 4. Code signing

Chances are that if you try to elevate your application you’ll get an ugly yellow elevation box:


To get the nice UAC box you’ll need to code sign your application. I won’t link to any code signing providers (because the list is huge), but you can get a code signing certificate from anywhere between $100 for 3 years to $400 or $500 for a single year. It depends on the company you use and the amount of searching you want to do.

7 Days of Windows 7

Join me tomorrow when I talk about Every possible Windows Vista and Windows 7 .NET Control You could ever want. See the full list of articles in the series.

In today’s tip I’m going to cover showing drag & drop icons. Specifically keeping the icon overlay shown when you drag files from Windows Explorer to your .NET application. Here’s a close-up of a user dragging files from a folder into wyBuild.

If we had used the normal .NET Framework interfaces for dragging files to wyBuild as soon as the cursor passes into the window the icons would disappear.

But, as you can see in the screenshot, the icons stay when dragging over our window. We can also set the drag & drop text to the current folder the user is dragging over.

How to add this to your app

This is one control I can’t take credit for. Adam Root from Microsoft wrote up a nice control on his blog in a post Shell Style Drag and Drop in .NET – Part 3. The control works for both Windows Form and Windows Presentation Foundation (WPF) applications.

He wrote a 3 part series, and it’s interesting if you want to dig into the nitty-gritty Windows API.

How we use Drag & Drop in wyBuild

We use the Windows Form control in wyBuild, but we have to use a little trickery to get it work right. Because Adam wrote the Drag & Drop control using a .NET Framework 3.5 language feature, and wyBuild is built using .NET Framework 2.0, we have to use this little trick from Daniel Moth.

Just add this snippet of code to your project and you’ll be all set to go.

//HACK: this is to support a .NET language 3.5 feature in .NET 2.0
//see, http://www.danielmoth.com/Blog/2007/05/using-extension-methods-in-fx-20.html
namespace System.Runtime.CompilerServices
{
    public class ExtensionAttribute : Attribute { }
}

7 Days of Windows 7

Join me tomorrow when I talk about Using shield icons, UAC, and process elevation. See the full list of articles in the series.