Click Event for Member of Label Array
I have a VS 2005 Beta 2 VB program that creates an array of labels at runtime ... several dozen of them. Is there some way to capture click events on these labels so that I can figure out which one was clicked? I am worrried because as I understand it the WithEvents clause cannot be used with arrays but I cannot help but think there isn't some way to do what I want to do. Here is how I created the array:
PrivateSub btnGo_Click(ByVal senderAs System.Object,ByVal eAs System.EventArgs)Handles btnGo.ClickDim iAsInteger
Dim jAsInteger
Dim cells(8, 8)As Label
For i = 0To 8
For j = 0To 8
cells(i, j) =New Label
cells(i, j).Width = 40
cells(i, j).Height = 40
cells(i, j).Text =CStr(i * 9 + j + 1)
cells(i, j).Top = 150 + i * 42
cells(i, j).Left = 200 + j * 42
cells(i, j).ForeColor = Color.Black
cells(i, j).BackColor = Color.LightBlue
cells(i, j).BorderStyle = BorderStyle.FixedSingle
cells(i, j).TextAlign = ContentAlignment.MiddleCenter
cells(i, j).AutoSize =False
Me.Controls.Add(cells(i, j))
Next
Next
EndSubThanks.
[2985 byte] By [
fripper] at [2007-12-16]
Great help, Johan ... you have solved my dilemma. Thank you. I am very slowly beginning to get my arms around VB .Net 2005 ... I wish there was a huge library of sample code for doing things like this. I miss the simply control array feature of VB 6 and have struggled with learning how to do the equivalent in Net.
Thanks again.