【发布时间】:2017-10-12 14:13:36
【问题描述】:
我已经创建了一个二维的 PictureBox 数组,我想给数组的所有元素添加一个 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 事件?
【问题讨论】:
-
既然控件的数量是硬编码的,为什么不把它们放在设计器中的表单上呢?您仍然可以将对它们的引用存储在数组中以进行循环。请注意,您的应用可能会泄漏,数组索引从 0 开始。请阅读How to Ask 并使用tour
标签: arrays vb.net multidimensional-array event-handling