add on click event to picturebox vb.net

前端 未结 2 1587
醉酒成梦
醉酒成梦 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.

    0 讨论(0)
  • 2021-01-13 16:57

    Substitute PictureBox1 with the name of your control.

    Private Sub PictureBox1_Click(sender As Object, e As EventArgs) Handles PictureBox1.Click
        'executes when PictureBox1 is clicked
    End Sub
    
    0 讨论(0)
提交回复
热议问题