Hello,
(I am using VS 2010 .NET 4.0)
I have a For loop that appears 20 Small Panels, and each panel has an inner label, and I want when I click the panel, a msgbox will show the conntent of the Label inside.
Like this:
I tried this:
And the PanelClick method:
But the error:
I don't know what is going on with the code. Please help me to fix it.
(I am using VS 2010 .NET 4.0)
I have a For loop that appears 20 Small Panels, and each panel has an inner label, and I want when I click the panel, a msgbox will show the conntent of the Label inside.
Like this:

I tried this:
VB.NET:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
For i As Integer = 0 To 20
'Statements to add the Panels and the Labels here
AddHandler panelA.MouseEnter, AddressOf PanelClick 'hover effect
AddHandler panelA.MouseLeave, AddressOf PanelLeave
Next
End sub
And the PanelClick method:
VB.NET:
Public Sub PanelClick(ByVal sender As System.Object, ByVal e As System.EventArgs)
Dim clickedpanel As Panel = DirectCast(sender, Panel)
clickedpanel.BackColor = Color.Pink
Dim lbl = clickedpanel.Controls.OfType(Of Label)().First
MessageBox.Show(lbl.Text)
End Sub
But the error:
VB.NET:
Error 1 'OfType' is not a member of 'System.Windows.Forms.Control.ControlCollection'. E:\vb\RSchat\vb1\Form1.vb 70 19 vb1
I don't know what is going on with the code. Please help me to fix it.