add on click event to picturebox vb.net

前端 未结 2 1588
醉酒成梦
醉酒成梦 2021-01-13 16:24

I have a flowLayoutPanel which I am programatically adding new panelLayouts to. Each panelLayout has a pictureBox within it. It\'s all working nicely, but I need to detect w

2条回答
  •  旧巷少年郎
    2021-01-13 16:43

    Use the AddHandler statement to subscribe to the Click event:

        AddHandler pic.Click, AddressOf pic_Click
    

    The sender argument of the pic_Click() method gives you a reference to the picture box back:

    Private Sub pic_Click(ByVal sender As Object, ByVal e As EventArgs)
        Dim pic As PictureBox = DirectCast(sender, PictureBox)
        ' etc...
    End Sub
    

    If you need additional info about the specific control, like an index, then you can use the Tag property.

提交回复
热议问题