Some time ago, Reverend Jim gave me some good advice on dynamically creating controls with VB.net. Following the advice, I created 26 Labels (with text A-Z) and a event handler for the click event of the labels. Now I need to determine WHICH label was clicked and the text of that specific label. Is there a way to do this? This is NOT for a school project. This is the code I have thus far:
Public Class Form1
Inherits System.Windows.Forms.Form
Public mylbl(26) As Label
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim lbl As Label
For x As Integer = 0 To 25
lbl = New Label
lbl.Size = New Drawing.Size(25, 25)
lbl.Name = "Label" & x
lbl.Location = New Point(20 * (x + 1), 25)
lbl.ForeColor = System.Drawing.Color.Blue
lbl.TextAlign = HorizontalAlignment.Center
lbl.Text = Chr(65 + x)
mylbl(x) = lbl
GroupBox1.Controls.Add(lbl)
AddHandler mylbl(x).Click, AddressOf Label_Click
Next
End Sub
Private Sub Label_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
End Sub
major_lost