Windows 7样式地址栏(Address Bar)控件实现

简介: 介绍 从Vista开始,地址栏就有了很大的改变,不知道大家有什么感觉,笔者觉得很方便,同时又兼容之前的功能,是个很不错的创新。不过,微软并不打算把这一很酷的功能提供给广大的开发人员。 本文提供了一个简单的Address Bar实现,使用.NET 2.0和VS2008. 它是基于一个简单的树型遍历实现的,同时适用于各种级联数据。

介绍

从Vista开始,地址栏就有了很大的改变,不知道大家有什么感觉,笔者觉得很方便,同时又兼容之前的功能,是个很不错的创新。不过,微软并不打算把这一很酷的功能提供给广大的开发人员。

本文提供了一个简单的Address Bar实现,使用.NET 2.0和VS2008. 它是基于一个简单的树型遍历实现的,同时适用于各种级联数据。

abe.png

Demo中提供的是一个非常简单的示例,可以浏览文件系统。这里这是展示它是如何工作的。

 

使用代码

了解实现最简单的办法就是直接下载源代码,然后打开玩玩看~

在Design-Time下将Address Bar Control拖入Form,然后再构造器中加入下面一行代码:

 

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

你只需要传入一个根节点,然后根节点就会为control提供信息。FileSystemNode包含Windows系统安装后的第一个逻辑盘信息。 要实现IAddressNode类型,有如下三个重要的方法需要自己实现:

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

总结

示例很简单,相对来说也是轻量级的实现。如果想用它操作输了FileSystemNode以外的数据,你只需要实现IAddressNode接口,任何级联结构(hierarchical structure)的数据都可以用它来呈现。

 

许可证

本文以及示例代码文件遵循The Code Project Open License(CPOL)

 

源码下载

附件:AddressBarExt2_1.zip

 

英文链接:Vista Style Address Bar for .NET 2.0/WinForms

相关文章