標籤:root fine 開發 one 一行代碼 cin border self iad
介紹
從Vista開始,地址欄就有了很大的改變,不知道大家有什麼感覺,筆者覺得很方便,同時又相容之前的功能,是個很不錯的創新。不過,微軟並不打算把這一很酷的功能提供給廣大的開發人員。
本文提供了一個簡單的Address Bar實現,使用.NET 2.0和VS2008. 它是基於一個簡單的樹型遍曆實現的,同時適用於各種級聯資料。
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). |
Windows 7樣式地址欄(Address Bar)控制項實現