Click here to Skip to main content
15,883,783 members
Articles / Programming Languages / C#
Article

Vista Controls

Rate me:
Please Sign up or sign in to vote.
4.83/5 (31 votes)
18 Apr 20074 min read 176.7K   5.4K   109   27
Windows Vista Controls that degrade gracefully on Legacy Windows

Screenshot - test.gif

Introduction

Vista Controls is a class library that provides the ability to use the new style controls on Microsoft Windows Vista.

.NET 2.0 applications that use the Treeview, Listview, OpenFileDialog, SaveFileDialog and FolderBrowserDialog classes provided in the System.Windows.Forms assembly will find that when they run on Windows Vista, they do not use the new, Vista-style look and feel, but instead continue to use the old, XP-style look and feel.

In Vista Controls you will find five replacement classes, that will use the Vista look and feel when running on Windows Vista, and the old style on older versions of Windows. This allows you to target both Windows Vista and other versions of Windows without any additional effort on your part.

Additionally, Vista Controls includes a new control added to Vista, the Command Link. Because this control doesn't exist in previous versions of Windows, an emulated version that mimics Vista look and feel is used on those Windows versions.

Using the code

The classes in Vista Controls have exactly the same public interface and functionality (with a few minor exceptions noted below), so you can just replace all instances of System.Windows.Forms.TreeView, System.Windows.Forms.ListView, System.Windows.Forms.FileDialog, System.Windows.Forms.OpenFileDialog, System.Windows.Forms.SaveFileDialog and System.Windows.Forms.FolderBrowserDialog with Vista_Api.TreeView, Vista_Api.ListView, Vista_Api.FileDialog, Vista_Api.OpenFileDialog. Vista_Api.SaveFileDialog and Vista_Api.FolderBrowserDialog respectively.

The Vista Controls classes automatically fall back to the regular look if the Vista style look and feel is not supported (if your application is running on older versions of Windows). This means that you can use these classes even if your application is not targeted exclusively at Windows Vista. These classes fully support all platforms targeted by the .NET Framework 2.0, and will use the best available appearance on each of them.

There are a few places where Vista Controls classes deviate from their counterparts in System.Windows.Forms:

  • The SupportMultiDottedExtensions property has no effect on the Vista style dialogs.
  • Because the "open as read-only" option is implemented not as a check box but as an option in the "Open" button drop down, setting the ReadOnlyChecked property has no effect on the Vista style dialogs. The ReadOnlyChecked property is still used to determine whether the user chose this option after the dialog is closed. For the VistaFolderBrowserDialog class:
  • The visual appearance and functionality of the Vista style folder dialog differs greatly from the old style. It is not recommended to use the FolderBrowserDialog class without testing your application in both Windows Vista and older Windows versions.
  • The RootFolder property has no effect on the Vista style dialog.
  • The ShowNewFolderButton property has no effect on the Vista style dialog; the button is always visible.
  • You can use the UseDescriptionForTitle property to indicate that you want the value of the Description property to be used as the dialog title instead for the Vista style dialog. This has no effect on the old style dialogs.
  • Also note that unlike the regular file dialogs, you cannot use the VistaDialogs if all you have is FileDialogPermission. Your application needs to have full trust to use the Vista Controls assembly.

Controls

Common Dialogs

The Open File, Save File and Open Folder common dialogs.

Screenshot - open.gif

C#
private void button6_Click(object sender, EventArgs e)
{
    Vista_Api.OpenFileDialog d = new Vista_Api.OpenFileDialog();
    d.ShowDialog();
}

Screenshot - save.gif

C#
private void button5_Click(object sender, EventArgs e)
{
    Vista_Api.SaveFileDialog d = new Vista_Api.SaveFileDialog();
    d.ShowDialog();
}

Screenshot - folder.gif

C#
private void button4_Click(object sender, EventArgs e)
{
    FolderBrowserDialog d = new FolderBrowserDialog();
    d.ShowDialog();
}

Command Links

Command links are a new control that presents options to the user with links instead of command buttons or radio buttons. They are the preferred approach when longer labels are needed to help users make informed choices. They also reduce the number of clicks required to make choices.

Screenshot - taskdialog.gif

C#
private void commandLink2_Click(object sender, EventArgs e)
{
    List<vista_api.commandlink> links=new List<vista_api.commandlink>();
    Vista_Api.CommandLink cl = new Vista_Api.CommandLink(
        Vista_Api.CommandLink.DisplayStyle.Arrow, "Lorem Ipsum", 
        "Lorem Ipsum");
    cl = new Vista_Api.CommandLink(Vista_Api.CommandLink.DisplayStyle.Arrow, 
        "Lorem Ipsum", "Lorem Ipsum");
    cl.BackColor = SystemColors.Window;
    links.Add(cl);
    cl = new Vista_Api.CommandLink(Vista_Api.CommandLink.DisplayStyle.Arrow, 
        "Lorem Ipsum", "Lorem Ipsum");
    cl.BackColor = SystemColors.Window;
    links.Add(cl);
    cl = new Vista_Api.CommandLink(Vista_Api.CommandLink.DisplayStyle.Shield, 
        "Lorem Ipsum", "Lorem Ipsum");
    cl.BackColor = SystemColors.Window;
    links.Add(cl);
    Vista_Api.CommandDialog cd = new Vista_Api.CommandDialog(links);
    cd.Title = "Lorem Ipsum";
    cd.Description = "Lorem Ipsum";
    cd.ShowDialog();
}
</vista_api.commandlink></vista_api.commandlink>

ListView and TreeView

TreeViews Enhancements:

  • Updated look.
  • Glyph fade in/out on mouse hover.
  • Expand/collapse node transition animation.

ListViews Enhancements:

  • Updated look.
  • Enables users to see more properties for a smaller set of items at a time without requiring awkward horizontal scrolling.
  • There is a hover state when hovering over items, with cross fade animation.
  • Other details include rollover and hover states that provide a view that looks interactive and responsive, and the themed transparent selection rectangles.

See the initial image for screen shots of these controls.

Points Of Interest

The detection of the Windows version is made in Vista_Api.Dialog.Native.NativeMethods.

C#
/// <value>
/// Returns true on Windows Vista or newer operating systems; otherwise, 
/// false.
/// </value>
[Browsable(false)]
public static bool IsVistaOrLater
{
    get
    {
        return Environment.OSVersion.Platform == 
            PlatformID.Win32NT && Environment.OSVersion.Version.Major >= 6;
    }
}

History

  • 1.0 (19 March, 2007): First release.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


Written By
Web Developer
Portugal Portugal
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

 
GeneralStrangely FolderBrowserDialog no longer be able to run Pin
Adikara Putra (Hikaru Yuuki)8-Jun-11 17:34
Adikara Putra (Hikaru Yuuki)8-Jun-11 17:34 
GeneralRe: Strangely FolderBrowserDialog no longer be able to run Pin
Adikara Putra (Hikaru Yuuki)8-Jun-11 17:54
Adikara Putra (Hikaru Yuuki)8-Jun-11 17:54 
GeneralNo need for SaveFileDialog and OpenFileDialog && Thanks for the FolderBrowserDialog Pin
Vercas7-Aug-10 10:37
Vercas7-Aug-10 10:37 
GeneralMy vote of 4 Pin
koolprasad200328-Jul-10 2:14
professionalkoolprasad200328-Jul-10 2:14 
GeneralMissing a Vista Control, the Task Dialog Pin
sevenalive29-Sep-08 17:07
sevenalive29-Sep-08 17:07 
QuestionLicense Pin
Julian-w20-May-08 3:54
Julian-w20-May-08 3:54 
QuestionCommandLnk Buttons Under XP Pin
jamalhaider17-Aug-07 21:31
jamalhaider17-Aug-07 21:31 
AnswerRe: CommandLnk Buttons Under XP Pin
yassir hannoun29-Jul-08 9:00
yassir hannoun29-Jul-08 9:00 
GeneralTreeView problems... Pin
Otto Doseth222-Jun-07 1:42
Otto Doseth222-Jun-07 1:42 
GeneralRe: TreeView problems... Pin
veritas guy11-Aug-07 18:41
veritas guy11-Aug-07 18:41 
AnswerRe: TreeView problems... Pin
jdsuchen from china12-May-09 20:05
jdsuchen from china12-May-09 20:05 
GeneralRe: TreeView problems... Pin
Xmen Real 13-May-10 14:47
professional Xmen Real 13-May-10 14:47 
GeneralSolution for FolderBrowserDialog in 64-bits! Pin
MichieL D7-Jun-07 3:46
MichieL D7-Jun-07 3:46 
GeneralThe same displayed Pin
Daniel Hover26-Apr-07 0:21
Daniel Hover26-Apr-07 0:21 
AnswerRe: The same displayed Pin
Pedro M. C. Cardoso26-Apr-07 3:46
Pedro M. C. Cardoso26-Apr-07 3:46 
GeneralRe: The same displayed Pin
Daniel Hover26-Apr-07 6:51
Daniel Hover26-Apr-07 6:51 
General! Pin
The_Mega_ZZTer19-Apr-07 3:44
The_Mega_ZZTer19-Apr-07 3:44 
QuestionAero Wizard Pin
André Ziegler7-Apr-07 8:56
André Ziegler7-Apr-07 8:56 
AnswerRe: Aero Wizard Pin
manishgour20071-Aug-07 23:44
manishgour20071-Aug-07 23:44 
QuestionDoes it work with .NET 1.1 Pin
nagarsoft7-Apr-07 3:19
nagarsoft7-Apr-07 3:19 
Does the controls work with .NET 1.1?
Thanks.
Andrea
AnswerRe: Does it work with .NET 1.1 Pin
Pedro M. C. Cardoso15-Apr-07 2:12
Pedro M. C. Cardoso15-Apr-07 2:12 
Generalbuttons Pin
pppier24-Mar-07 21:30
pppier24-Mar-07 21:30 
AnswerRe: buttons Pin
Pedro M. C. Cardoso27-Mar-07 0:32
Pedro M. C. Cardoso27-Mar-07 0:32 
AnswerDeselection Problem Pin
ERobishaw3-May-07 19:28
ERobishaw3-May-07 19:28 
GeneralRe: Deselection Problem Pin
Alexander Stetsenko21-Jun-07 0:51
Alexander Stetsenko21-Jun-07 0:51 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.