[VB.NET]Get All Nodes Under a TreeView or TreeNode

若要取得TreeView或TreeNode下的所有節點,可以透過遞迴的方式把所有節點給找出來。像是下面這樣: Private Function GetAllNodes(ByVal treeOrNode As Object) As TreeNode() If Not TypeOf treeOrNode Is TreeNode AndAlso Not TypeOf treeOrNode Is TreeView Then Throw New ArgumentException("Error param type!!") End If Dim nodes As New List(Of TreeNode) If TypeOf treeOrNode Is TreeNode Then nodes.Add(treeOrNode) End If For Each tn As TreeNode In treeOrNode.Nodes nodes.AddRange(GetAllNodes(tn)) Next Return nodes.ToArray End Function 使用上把TreeView或是TreeNode當作參數帶入即可,也可以整理成擴充方法使用: Imports System.Runtime.CompilerServices Public Module TreeViewExtension #Region "Private Method" Private Function GetAllTreeNodes(ByVal treeOrNode As Object) As TreeNode() If Not TypeOf treeOrNode Is TreeNode AndAlso Not TypeOf treeOrNode Is TreeView Then Throw New ArgumentException("Error param type!!") End If Dim nodes As New List(Of TreeNode) If TypeOf treeOrNode Is TreeNode Then nodes.Add(treeOrNode) End If For Each tn As TreeNode In treeOrNode.Nodes nodes.AddRange(GetAllTreeNodes(tn)) Next Return nodes.ToArray End Function #End Region #Region "Public Method" <Extension()> _ Public Function GetAllNodes(ByVal tree As TreeView) As TreeNode() Return GetAllTreeNodes(tree) End Function <Extension()> _ Public Function GetAllNodes(ByVal node As TreeNode) As TreeNode() Return GetAllTreeNodes(node) End Function #End Region End Module

February 9, 2010 · Larry Nung

[Visual Studio]Fixldquo;The application cannot startrdquo;

最近在使用Visual Studio 2010 Beta2,開啟時出現"The application cannot start"的錯誤,按下確定後Visual Studio就自動關閉了。 ...

February 3, 2010 · Larry Nung

[Visual Studio]Visual Studio 2010 New Feature - Call Hierarchy

Introduction Call Hierarchy是Visual Studio 2010的新功能之一,能讓開發人員快速的找到類別成員被參考使用到的地方、其所使用到的其它類別成員、覆寫的地方、與實作的地方。以往這樣的動作我們可能要透過搜尋、[Go To Define]、與[Find All References]來完成。透過Visual Studio 2010 Call Hierarchy的新功能,我們可以更為輕鬆快速的達到這個目的。 ...

January 31, 2010 · Larry Nung

[VB.NET]Extract Frames from an Animated GIF

要取得Gif動畫圖檔內含的圖片,必須要了解的有Bitmap.FrameDimensionsList、FrameDimension Class、Bitmap.GetFrameCount、與Bitmap.SelectActiveFrame。 ...

January 24, 2010 · Larry Nung

[C#][VB.NET]FullScreen the winform

在.NET程式中,若想要把視窗設為全螢幕,我們可以很簡單的透過FormBorderStyle與WindowState兩個屬性來完成。只要把視窗的FormBorderStyle屬性設為None,並把WindowState屬性設為Maximized,視窗就會變為全螢幕顯示。程式碼如下: ...

January 24, 2010 · Larry Nung

[VB.NET]Add a Loading Animation to a Control

最近有個需求是當程式在做複雜的運算時,需要告知使用者程式仍然運作,而若用彈出單一Loading對話框的方式又不太適用,因此會想跟網頁一樣能在控制項上外加載入動畫。 ...

January 24, 2010 · Larry Nung

[VB.NET]Change MDI Parent BackColor

最近在調整MDI背景顏色時,發現MDI的背景顏色不能直接設定。直接設定的話會像下圖一樣,會看不到預期的結果。 ...

January 23, 2010 · Larry Nung

[Other]Acceptance Speech for the Microsoft 2009 Annual Forum Contribution Award

收到微軟的禮物了~Microsoft 2009 年度論壇貢獻獎Q版小公仔(隱藏版)一座。 ...

January 23, 2010 · Larry Nung

[Visual Studio]Visual Studio 2010 New Feature - Reference Highlight

Highlight Reference是Visual Studio 2010新增的貼心小功能,能幫我們快速的找到程式中參考到的地方,並提供快速的巡覽。 ...

January 21, 2010 · Larry Nung

[Visual Studio]Visual Studio 2010 New Feature - Navigate To

Visual Studio 2010新增Navigate To搜尋功能,能快速的搜尋資料。 ...

January 20, 2010 · Larry Nung