ItemCollection is a collection of strings with names for a new control, newPage is a Form, and SkinnedItem is a Class which inherits a panel, and has a few extra properties
Here is the initial adding of the controls
Dim strInfo As String
'Add each Item to the page
For Each strInfo In itemCollection
Dim newItem As New SkinnedItem()
'Set Item Properties
newItem.Name = strInfo
newItem.SetItemProps(newItem, strInfo)
newItem.Initialize
'Add the Button
newPage.Controls.Add(newItem)
Next
This is the code in the initialize method for a SkinnedItem which attaches the events
Public Sub Initialize()
AddHandler Me.MouseEnter, AddressOf Mouse_Enter
AddHandler Me.MouseLeave, AddressOf Mouse_Leave
AddHandler Me.MouseUp, AddressOf Mouse_Up
AddHandler Me.MouseDown, AddressOf Mouse_Down
End Sub
Here is the SetItemProps method
Public Sub SetItemProps(ByVal Item As Object, ByVal ItemName As String, optional EventName as string)
Select Case EventName
Case "onmouseenter"
Item.BackgroundImage = Image.FromFile("C:\temp\image1.jpg")
End Select
End Sub
And here is the Event Code
Public Sub Mouse_Enter(ByVal sender As Object, ByVal e As System.EventArgs)
If sender.GetType.Name.ToString = "SkinnedItem" Then
SetItemProps(sender, sender.name, "onmouseenter")
End If
End Sub
I had to simplify some of the code, to make it understandable as I am reading all the properties for each event from an xml file, but if you don't see anything in this... I could attach the project.
Thanks a bunch,
liquid8