我有一个用户需要单击的10x10图片框阵列,我显然太懒了,无法编写100个单独的“ Picturebox.Onclick”-段落,每个数组对应一个。我该怎么办?
我知道的唯一方法是每个Picturebox都有一个Paragraph,而我最多可以做到8个Picturebox。但是100? Naaahhh。 我知道必须有一种更简单的方法,但我无法弄清楚。
答案 0 :(得分:1)
您可以将图片框数组转换为列表,然后将处理程序添加到列表中项目的鼠标单击事件。像这样
Dim piclist As New List (Of PictureBox)
'Convert 2d array to 1d array and store in a List
'***********************
' Replace picarr with the name of your picture box array
For x As Integer = 0 To 9
For y As Integer = 0 To 9
piclist.Items.Add(picarr(x,y)
Next
Next
'*************************
For Each item As PictureBox in piclist
AddHandler item.Click, AddressOf picclick
Next
Public Sub picclick (sender As Object, e As EventArgs)
'Add actions here
End Sub