In my project, I have two seperate forms and in one of them I can add various panels using a button. After adding let's say 5 panels I click on one of them and I need the code to tell me which panelI clicked on. The reason I need this is to refrence the clicked panel's information on the other form. So if the user clicks on panel 3, the other form shows up and tells me you clicked on panel 3. here's what I have so far.

    Private Sub Button_Click(ByVal sender As System.Object, ByVal e As ClickEventArgs) Handles Button.Click
        For Each Panel In FlowLayoutPanel1.Controls.OfType(Of PanelControl)()
        AddHandler Panel.Click, AddressOf Panel_Click
    End Sub

    Private Sub Panel_Click(ByVal sender As Object, ByVal e As EventArgs)
        Form.Label.Text = "You clicked on" & sender
    End Sub

Edited 4 Years Ago by boher: wrong code

Thanks man, that did the trick.

--> TryCast(sender, Panel)


This question has already been answered. Start a new discussion instead.