Imports System.Reflection
Public Class ClassBox
Public Class ItemClickedArgs
Inherits EventArgs
Private _Item As ItemBox
Public Property Item() As ItemBox
Get
Return _Item
End Get
Set(ByVal value As ItemBox)
_Item = value
End Set
End Property
Sub New(ByVal Item As ItemBox)
Me.Item = Item
End Sub
End Class
Public Delegate Sub ItemClickedHandler(ByVal sender As Object, ByVal e As ItemClickedArgs)
Public Event ItemClicked As ItemClickedHandler
Private _Color As Color = Drawing.Color.Blue
Private _Collapsed As Boolean = True
Private TypeName As String
Private IsMouseDown As Boolean = False
Private IsResizing As Boolean = False
Private MousePos As Point
Private IdealWidth, IdealHeight As Int32
Public Property Color() As Color
Get
Return _Color
End Get
Set(ByVal value As Color)
_Color = value
End Set
End Property
Public Property Collapsed() As Boolean
Get
Return _Collapsed
End Get
Set(ByVal value As Boolean)
_Collapsed = value
If value Then
Dim StrSize As SizeF = Me.CreateGraphics.MeasureString(TypeName, Me.Font, 1000)
Me.Size = New Size(StrSize.Width + 10, 75)
If Me.Width < 60 Then
Me.Width = 60
End If
End If
For Each C As Control In Me.Controls
C.Visible = Not value
Next
End Set
End Property
Private Function CreateItemBox(ByVal MI As MemberInfo) As ItemBox
Dim M As New ItemBox
'M.Location = New Point(Me.Width * 6 / 100 - 1, 35 + Y)
'M.Size = New Size(Me.Width * 88 / 100, 35)
M.Color = M.DefaultColors(MI.MemberType)
M.BackColor = Drawing.Color.Transparent
M.ForeColor = Drawing.Color.Black
M.Text = MI.Name
M.Tag = MI
M.Name = MI.Name
Return M
End Function
Public Sub Minimize()
Me.Collapsed = True
Me.Refresh()
End Sub
Public Sub Miniature()
End Sub
Public Sub ClearAll()
Me.Controls.Clear()
Me.Minimize()
End Sub
Public Sub ScanClass(ByVal T As Type, Optional ByVal Maximized As Boolean = False)
Dim Properties As New ArrayList
Dim Methods As New ArrayList
Dim Events As New ArrayList
Dim Fields As New ArrayList
Dim Types As New ArrayList
Dim Members As MemberInfo() = T.GetMembers
Dim M As ItemBox
Me.Controls.Clear()
TypeName = AssemblyScanner.GetTypeName(T)
For Each MI As MemberInfo In Members
M = CreateItemBox(MI)
If MI.MemberType <> MemberTypes.Constructor And MI.MemberType <> MemberTypes.Custom And MI.MemberType <> MemberTypes.TypeInfo Then
If Not Me.Controls.ContainsKey(M.Name) Then
Me.Controls.Add(M)
Else
With DirectCast(Me.Controls(M.Name), ItemBox)
.ExposedMembers.Add(MI)
End With
End If
AddHandler M.Click, AddressOf ItemClickHandler
End If
Select Case MI.MemberType
Case MemberTypes.Event
Events.Add(MI)
Case MemberTypes.Field
Fields.Add(MI)
Case MemberTypes.Method
Methods.Add(MI)
Case MemberTypes.NestedType
Types.Add(MI)
Case MemberTypes.Property
Properties.Add(MI)
End Select
Next
Dim Entries As New ArrayList
For Each L As ArrayList In New ArrayList() {Events, Fields, Methods, Types, Properties}
If L.Count >= 1 Then
Entries.Add(L)
End If
Next
If Entries.Count = 0 Then
Me.ClearAll()
Exit Sub
End If
If Me.Width < Entries.Count * 70 Then
Me.Width = Entries.Count * 75
End If
Dim AvgWidth As Int32 = (Me.Width - 10 - 5 * Entries.Count) / Entries.Count
Dim X, Y, YMax As Int32
If True Then
AvgWidth = 100
Me.Width = Entries.Count * 105 + 10
End If
X = 5
Y = 35
For Each Entry As ArrayList In Entries
Y = 35
For Each MI As MemberInfo In Entry
With DirectCast(Me.Controls(MI.Name), ItemBox)
If Y > Me.Height - 50 Then .Visible = False
If .Overloaded Then Continue For
.Location = New Point(X, Y)
.Size = New Size(AvgWidth, 35)
.Overloaded = True
End With
Y += 36
If Y > YMax Then YMax = Y
Next
X += AvgWidth + 5
Next
IdealHeight = YMax + 40
IdealWidth = Entries.Count * 105 + 10
Me.Height = IdealHeight
Me.Width = IdealWidth
Me.Collapsed = False
Me.Refresh()
End Sub
Public Sub SetTypeName(ByVal T As Type)
Dim Name As String = AssemblyScanner.GetTypeName(T)
Dim MinWidth As Int32 = Me.CreateGraphics.MeasureString(Name, Me.Font, 1000).Width
TypeName = Name
If T.IsInterface Then
Me.Color = Drawing.Color.Fuchsia
ElseIf T.IsEnum Then
Me.Color = Drawing.Color.DarkOrange
ElseIf T.IsValueType Then
Me.Color = Drawing.Color.DarkGreen
End If
Me.Collapsed = True
End Sub
Private Sub ClassBox_Paint(ByVal sender As System.Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles MyBase.Paint
Dim H As New Header
Dim F As New Footer
Dim B As New Block
'Header, 20%
H.Location = New Point(0, 0)
H.Size = New Size(Me.Width - 1, Me.Height / 5)
H.Color = Me.Color
'Footer, 20%
F.Location = New Point(0, Me.Height * 4 / 5 - 1)
F.Size = New Size(Me.Width - 1, Me.Height / 5)
F.Color = Me.Color
'Block, 60%
B.Location = New Point(0, Me.Height / 5)
B.Size = New Size(Me.Width - 1, Me.Height * 3 / 5 + 1)
B.Color = Me.Color
e.Graphics.SmoothingMode = Drawing2D.SmoothingMode.AntiAlias
H.Draw(e.Graphics)
B.Draw(e.Graphics)
F.Draw(e.Graphics)
Dim TextSize As SizeF = e.Graphics.MeasureString(TypeName, Me.Font, 1000)
If Not Collapsed Then
Dim C As Color = Me.ForeColor
If Me.Height > 300 Then C = Drawing.Color.Black
e.Graphics.DrawString(TypeName, Me.Font, New SolidBrush(C), Me.Width / 2 - TextSize.Width / 2, 5)
Else
e.Graphics.DrawString(TypeName, Me.Font, New SolidBrush(Me.ForeColor), Me.Width / 2 - TextSize.Width / 2, Me.Height / 2 - TextSize.Height / 2)
End If
End Sub
Private Sub ClassBox_MouseDown(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles MyBase.MouseDown
MousePos = New Point(MousePosition.X - Me.Location.X, MousePosition.Y - Me.Location.Y)
IsMouseDown = True
End Sub
Private Sub ClassBox_MouseUp(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles MyBase.MouseUp
IsMouseDown = False
End Sub
Private Sub ClassBox_MouseMove(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles MyBase.MouseMove
If IsMouseDown Then
Me.Location = New Point(MousePosition.X - MousePos.X, MousePosition.Y - MousePos.Y)
End If
End Sub
Private Sub ItemClickHandler(ByVal sender As Object, ByVal e As EventArgs)
RaiseEvent ItemClicked(Me, New ItemClickedArgs(DirectCast(sender, ItemBox)))
End Sub
End Class