David,
As the example shows: the "sender" parameter is the label that was clicked.
You could assign the label to a locally typed variable
' VS 2005 syntax
> Sub SomeClick(sender as object, e as System.EventArgs)
Dim theLabel As Label = DirectCast(sender, Label)
If theLabel.BackColor = Color.Black Then
theLabel.BackColor = Color.Red
Else
theLabel.BackColor = Color.Black
End If
> End Sub
When you created the label you could use the Label.Tag (inherited from
Control) property to track extra information about the Label. In addition to
Label.Tag I normally use Inheritance to add additional info, via new fields
& properties to the Label control.
Public Class CustomLabel
Inherits Label
Private m_row As Integer
Private m_column As Integer
Public Property Row() As Integer
Get
Return m_row
End Get
Set(ByVal value As Integer)
m_row = value
End Set
End Property
Public Property Column() As Integer
Get
Return m_column
End Get
Set(ByVal value As Integer)
m_column = value
End Set
End Property
End Class
> for i = 1 to 12
for j = 1 to 12
dim lbl as new CustomLabel
AddHandler lbl.Click, AddressOf SomeClick
me.controls.add(lbl)
with lbl
.Row = i
.Column = j
> ...
end with
next
next
--
Hope this helps
Jay B. Harlow
..NET Application Architect, Enthusiast, & Evangelist
T.S. Bradley -
http://www.tsbradley.net
"David Pick" <pi*******@gmail.comwrote in message
news:11*********************@i3g2000cwc.googlegrou ps.com...
Thanks that worked great. Is there any way to figure out which label
was being click?
Josip Medved wrote:
I would like to have it so that if one of these labels were click it
would change color. Any help would be appreciated. Thanks
First create sub:
Sub SomeClick(sender as object, e as System.EventArgs)
DirectCast(sender, Label).BackColor = Color.Red
End Sub
If your for use AddHandler like this:
for i = 1 to 12
for j = 1 to 12
dim lbl as new label
AddHandler lbl.Click, AddressOf SomeClick
me.controls.add(lbl)
with lbl
...
end with
next
next
This should do it.
--
Pozdrav,
Josip Medved
http://www.jmedved.com