Author:水如烟
因为但求简单实现,自己也不深究,所以做出来比较粗糙。马马虎虎应付过去。
效果图:
控件代码见应用类代码:LzmTW.uSystem.uWindows.uForms + ToolPanelTree
Imports System.Reflection
Public Class Form1
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Me.ToolStripButton1.Image = LzmTW.ResourceBitmap.GetMagenta(GetType(DataGridView), "DataGridView.bmp")
End Sub
Private Sub ToolStripButton1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles ToolStripButton1.Click
Dim mNode1 As TreeNode = AssemblyStaticMethodNode(GetType(Object))
Dim mNode2 As TreeNode = AssemblyStaticMethodNode(GetType(Microsoft.VisualBasic.Strings))
With Me.ToolPanelTree1.TreeView
.BeginUpdate()
.Nodes.Clear()
.Nodes.AddRange(New TreeNode() {mNode1, mNode2})
.Sort()
.EndUpdate()
End With
End Sub
Public Function AssemblyStaticMethodNode(ByVal t As Type) As TreeNode
Dim mAssembly As Assembly = Assembly.GetAssembly(t)
Dim mRootNode As New TreeNode(mAssembly.GetName.Name)
Dim mSecondNode As TreeNode = Nothing
Dim mCurrentNode As TreeNode = Nothing
Dim mCurrentTypeChanged As Boolean = False
Dim mBinding As BindingFlags = BindingFlags.Public & BindingFlags.Static
For Each mModule As [Module] In mAssembly.GetModules
mSecondNode = mRootNode.Nodes.Add(mModule.ScopeName)
For Each mType As Type In mModule.GetTypes
If mType.IsClass Then
mCurrentTypeChanged = True
For Each mMethod As MethodInfo In mType.GetMethods(mBinding)
If mCurrentTypeChanged Then
mCurrentNode = mSecondNode.Nodes.Add(mType.FullName)
mCurrentTypeChanged = False
End If
mCurrentNode.Nodes.Add(mMethod.ToString)
Next
End If
Next
Next
Return mRootNode
End Function
End Class
上面用到的一个函数,是这样(临时的,所以还不用贴上来)
Namespace LzmTW
Public Class ResourceBitmap
Private Sub New()
End Sub
Public Shared Function [Get](ByVal t As Type, ByVal name As String) As Bitmap
Return New Bitmap(t, name)
End Function
Public Shared Function GetMagenta(ByVal t As Type, ByVal name As String) As Bitmap
Dim mBitmap As Bitmap = [Get](t, name)
mBitmap.MakeTransparent(Color.Magenta)
Return mBitmap
End Function
End Class
End Namespace