Introduction

Whilst Windows Vista still sits in amidst much controversy and discussion, a few of the features/changes it implemented have been quite cool. However, Microsoft failed to really let slide some of the cool UI changes down to us normal (or student) developers.

This article/code sample contains a personal implementation of the Vista-Style address bar for use in .NET/WinForms applications. It's based around a simple Tree/Node traversal that can be inherited to browse whatever you like.

Included in the demo is an example implementation that browses the file system tree, though it is limited in functionality (it was only made to illustrate how it all works ).

Using the Code

The easiest way to understand the code is to download it and open it and have a play about.

The simplest way to use the bar is to drop it onto your form in Design view, then in the constructor of your form add the following code:

//Initialize the bar with a root node type.
this.AdBar.InitializeRoot(new FileSystemNode());

All you need to do is pass it a root node, and the node itself should provide the information directly to the control. The FileSystemNode provides a basic enumeration of the first logical drive found on your Windows Install.

To implement the IAddressNode class, there are a few simple Properties to override and implement, then three real methods to implement yourself:

UpdateNode() - Used to update the node itself for any changes (e.g. in the FileSystemNode it checks for child folder changes and folder name changes)

GetChild() - Searches for a given child node based on a unique ID (A Unique ID being whatever you define it as. In FileSystemNode, we use an absolute path for a folder as the unique ID).

Clone() - Clones a given node as a separate value copy (rather than just by reference).

Conclusion

It's simple and relatively lightweight, it just needs you to implement your own IAddressNode derivatives to let it traverse any hierarchical structure you see fit.

Comments and Discussions

I have the address bar in a limited space (i.e. width is 282). There are a few problems I've found:

1) When the overflow button is added (the one with ".." which has a drop down menu taking you back to the root) the following button which shows the current folder doesn't have a drop down button next to it therefore not allowing you to move to any further folders.

In order to fix this problem in the CreateOverflowDropDown() method change the following code from:

2) Another problem is that once the overflow has occurred there will only ever be the ".." button and the button with the current folder that you're in. From this point on, traversing to any other folders will only ever show the above two buttons even though there may be space for more.

Otherwise you have made a fantastic control! Just be careful to wrap all yours statements (especially your if else statements) with brackets.