如何为以编程方式创建的PictureBox数组创建事件处理程序?

时间:2017-10-12 14:13:36

标签: arrays vb.net multidimensional-array event-handling

我创建了一个PictureBoxes的二维数组,我想将DragDrop事件添加到数组的所有元素中。

 For x As Integer = 1 To 16
        For y As Integer = 1 To 4
            p(x, y) = New PictureBox()
            p(x, y).Image = My.Resources.Kästchen
            p(x, y).Location = New Point(pMain.Left + x * 48, pMain.Top + y * 48)
            p(x, y).Size = New Size(48, 48)
            p(x, y).Name =  "p"+str(x)+str(y)
            AddHandler p(x, y).DragDrop, AddressOf p(x,y)_DragDrop

            p(x, y).Visible = True
            Me.Controls.Add(p(x, y))


        Next
    Next

我知道有类似的答案here,但我无法将其改编为数组。 如何为运行时创建的所有PictureBox添加DragDrop事件?

1 个答案:

答案 0 :(得分:1)

您不能拥有名为p(x,y)_DragDrop的子广告。您需要创建一个包含签名(sender As Object, e As DragEventArgs)的子广告,并使用sender来识别图片框。

相关问题