A quick example to illustrate what you can do to get the selected effect
vb Code:
Public Class Form3
Private Sub Form3_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
CreatePicBox()
End Sub
Private Sub CreatePicBox()
Dim picBox As PictureBox
Dim x As Integer = 10
Dim y As Integer = 10
For i As Integer = 1 To 3
picBox = New PictureBox
With picBox
.Name = "PictureBox" & i
.Size = New Size(40, 40)
.Location = New Point(x, y)
.BorderStyle = BorderStyle.Fixed3D
x += 50
End With
AddHandler picBox.Click, AddressOf picBox_Click
Me.Controls.Add(picBox)
Next
End Sub
Private Sub picBox_Click(ByVal sender As Object, ByVal e As System.EventArgs)
'Remove handlers from all picture boxes
Dim pb As PictureBox
For Each ctrl As Control In Me.Controls
If TypeOf ctrl Is PictureBox Then
pb = DirectCast(ctrl, PictureBox)
RemoveHandler pb.Paint, AddressOf picBox_Paint
pb.Invalidate()
End If
Next
'add handler to the clicked picturebox
pb = DirectCast(sender, PictureBox)
AddHandler pb.Paint, AddressOf picBox_Paint
pb.Invalidate()
End Sub
Private Sub picBox_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs)
Dim pb As PictureBox = DirectCast(sender, PictureBox)
Dim rect As Rectangle = pb.ClientRectangle
Dim p As Pen = New Pen(Color.Blue, 3)
e.Graphics.DrawRectangle(p, rect)
End Sub
End Class