Ok, complete code for my inherited class is:
Option Strict On
Imports Iris.AccountsProduction.Reporting.Tools
#Region "Properties"
Dim ColorStyles As VisualStyles.VisualStyle
Dim MoreColorsGraphics As Graphics
Dim mColor As Color
Public Property Color() As Color
Get
Return mColor
End Get
Set(ByVal Value As Color)
mColor = Value
RaiseEvent SelectionChanged(New ColorMenuItem(mColor), New
EventArgs)
End Set
End Property
#End Region
#Region "Constructors"
Public Sub New()
MyBase.New()
ColorStyles = New VisualStyles.VisualStyle
InitilizeColors()
InitilizeEventHandlers()
End Sub
#End Region
#Region "Events"
Public Event SelectionChanged As EventHandler
#End Region
#Region "Initilize"
Private Sub InitilizeColors()
Dim MoreColors As MenuItem
MenuItems.Add(New ColorMenuItem(Color.Black))
MenuItems.Add(New ColorMenuItem(Color.DarkRed))
MenuItems.Add(New ColorMenuItem(Color.Red))
MenuItems.Add(New ColorMenuItem(Color.Pink))
MenuItems.Add(New ColorMenuItem(Color.Pink))
MenuItems.Add(New MenuItem("0"))
MenuItems.Add(New ColorMenuItem(Color.Brown, True))
MenuItems.Add(New ColorMenuItem(Color.Orange))
MenuItems.Add(New ColorMenuItem(Color.Orange))
MenuItems.Add(New ColorMenuItem(Color.Gold))
MenuItems.Add(New ColorMenuItem(Color.Tan))
MenuItems.Add(New MenuItem("1"))
MenuItems.Add(New ColorMenuItem(Color.Olive, True))
MenuItems.Add(New ColorMenuItem(Color.Yellow))
MenuItems.Add(New ColorMenuItem(Color.Lime))
MenuItems.Add(New ColorMenuItem(Color.Yellow))
MenuItems.Add(New ColorMenuItem(Color.LightYellow))
MenuItems.Add(New MenuItem("2"))
MenuItems.Add(New ColorMenuItem(Color.DarkGreen, True))
MenuItems.Add(New ColorMenuItem(Color.Green))
MenuItems.Add(New ColorMenuItem(Color.SeaGreen))
MenuItems.Add(New ColorMenuItem(Color.Green))
MenuItems.Add(New ColorMenuItem(Color.LightGreen))
MenuItems.Add(New MenuItem("3"))
MenuItems.Add(New ColorMenuItem(Color.Teal, True))
MenuItems.Add(New ColorMenuItem(Color.Teal))
MenuItems.Add(New ColorMenuItem(Color.Aqua))
MenuItems.Add(New ColorMenuItem(Color.Turquoise))
MenuItems.Add(New ColorMenuItem(Color.Turquoise))
MenuItems.Add(New MenuItem("4"))
MenuItems.Add(New ColorMenuItem(Color.DarkBlue, True))
MenuItems.Add(New ColorMenuItem(Color.Blue))
MenuItems.Add(New ColorMenuItem(Color.LightBlue))
MenuItems.Add(New ColorMenuItem(Color.SkyBlue))
MenuItems.Add(New ColorMenuItem(Color.Blue))
MenuItems.Add(New MenuItem("5"))
MenuItems.Add(New ColorMenuItem(Color.Indigo, True))
MenuItems.Add(New ColorMenuItem(Color.Violet))
MenuItems.Add(New ColorMenuItem(Color.Plum))
MenuItems.Add(New ColorMenuItem(Color.Lavender))
MenuItems.Add(New MenuItem("6"))
MenuItems.Add(New ColorMenuItem(Color.Gray, True))
MenuItems.Add(New ColorMenuItem(Color.Gray))
MenuItems.Add(New ColorMenuItem(Color.Gray))
MenuItems.Add(New ColorMenuItem(Color.White))
MenuItems.Add(New MenuItem("7"))
End Sub
Private Sub InitilizeEventHandlers()
Dim ChildItem As MenuItem
For Each ChildItem In MenuItems
If ChildItem.GetType Is GetType(ColorMenuItem) Then
AddHandler CType(ChildItem,
ColorMenuItem).ItemChecked, AddressOf ItemChecked
AddHandler CType(ChildItem,
ColorMenuItem).ItemSelected, AddressOf ItemSelected
Else
ChildItem.OwnerDraw = True
AddHandler ChildItem.MeasureItem, AddressOf
MoreColors_MeasureItem
AddHandler ChildItem.DrawItem, AddressOf
MoreColors_DrawItem
End If
Next
End Sub
#End Region
#Region "Drawing"
Dim MoreColorsSelected As Boolean
Private Sub MoreColors_MeasureItem(ByVal sender As Object, ByVal e
As MeasureItemEventArgs)
e.ItemHeight = 25
e.ItemWidth = 3
End Sub
Private Sub MoreColors_DrawItem(ByVal sender As Object, ByVal e As
DrawItemEventArgs)
If MoreColorsSelected Then Exit Sub
MoreColorsGraphics = e.Graphics
Dim Button As MenuItem = CType(sender, MenuItem)
Dim r As Rectangle = e.Bounds
Dim p As Pen
r.Height -= 5
r.Width = 148
r.X -= CInt(Button.Text) * 19
r.Y += 5
e.Graphics.FillRectangle(New SolidBrush(ColorStyles.TabPage),
r)
r.Height -= 1
r.Width -= 1
If CBool(e.State And DrawItemState.Selected) Then
e.Graphics.FillRectangle(New
SolidBrush(ColorStyles.Highlight), r)
e.Graphics.DrawRectangle(New Pen(Color.Black), r)
MoreColorsSelected = True
Else
MoreColorsSelected = False
End If
Dim TextSize As SizeF = e.Graphics.MeasureString("More
Colours...", SystemInformation.MenuFont)
Dim TextPos As PointF
TextPos.X = (r.Width - TextSize.Width) / 2
TextPos.Y = r.Y + ((r.Height - TextSize.Height) / 2)
e.Graphics.DrawString("More Colours...",
SystemInformation.MenuFont, SystemBrushes.ControlText, TextPos)
End Sub
#End Region
#Region "Implementation"
Private Sub ItemChecked(ByVal sender As Object, ByVal e As
EventArgs)
Dim ChildItem As MenuItem
For Each ChildItem In MenuItems
If Not (ChildItem Is sender) Then ChildItem.Checked =
False
Next
RaiseEvent SelectionChanged(sender, e)
End Sub
Private Sub ItemSelected(ByVal sender As Object, ByVal e As
EventArgs)
If MoreColorsSelected = False Then Exit Sub
MoreColorsSelected = False
Dim d As New DrawItemEventArgs(MoreColorsGraphics,
SystemInformation.MenuFont, New Rectangle, 5,
DrawItemState.NoAccelerator)
MoreColors_DrawItem(MenuItems(5), d)
End Sub
#End Region
End Class