Ciao.
Lascia perdere la collezione di bottoni .....
Usa questo codice e poi facci sapere....
Ciao
Module Module1
Public AnteprimaEtichetta() As PictureBox
Public MyPicture As PictureBox
Public Bottoni As New Collection()
Public Sub Crea(ByVal Contenitore As Windows.Forms.Panel)
Dim i As Integer
For i = 0 To 1 '1 E' SOLO PER ESEMPIO...
'======================
'CREO LE PICTUREBOX SUL FORM
ReDim Preserve AnteprimaEtichetta(i)
AnteprimaEtichetta(i) = New PictureBox
AnteprimaEtichetta(i).Tag = i
AnteprimaEtichetta(i).Left = 20
AnteprimaEtichetta(i).Top = 10
AnteprimaEtichetta(i).Size = New Size(50, 50)
AnteprimaEtichetta(i).WaitOnLoad = True
AnteprimaEtichetta(i).SizeMode = PictureBoxSizeMode.StretchImage
AnteprimaEtichetta(i).Cursor = Cursors.Hand
AnteprimaEtichetta(i).BackColor = Color.LightGray
AddHandler AnteprimaEtichetta(i).Click, AddressOf PictureClick
Contenitore.Controls.Add(AnteprimaEtichetta(i))
Next
End Sub
Public Sub PictureClick(ByVal sender As Object, ByVal e As EventArgs)
MyPicture = CType(sender, PictureBox)
Dim obj As Object = MyPicture
Dim IsForm As Boolean
While Not IsForm
If TypeOf DirectCast(obj, Control).Parent Is Form Then
IsForm = True
obj = DirectCast(obj, Control).Parent
Else
obj = DirectCast(obj, Control).Parent
End If
End While
Dim frm As Form = CType(obj, Form)
If MyPicture.BorderStyle = BorderStyle.None Then
MyPicture.BorderStyle = BorderStyle.FixedSingle
For Each cnt As Control In frm.Controls
If TypeOf cnt Is Panel Then
For Each _cnt As Control In cnt.Controls
If _cnt.Name = "Button2" Then
DirectCast(_cnt, Button).Enabled = True
End If
Next
End If
If cnt.Name = "Button2" Then
DirectCast(cnt, Button).Enabled = True
End If
Next
Else
MyPicture.BorderStyle = BorderStyle.None
For Each cnt As Control In frm.Controls
If TypeOf cnt Is Panel Then
For Each _cnt As Control In cnt.Controls
If _cnt.Name = "Button2" Then
DirectCast(_cnt, Button).Enabled = True
End If
Next
End If
If cnt.Name = "Button2" Then
DirectCast(cnt, Button).Enabled = False
End If
Next
End If
End Sub
End Module