AddHandler Pic.Click, AddressOf Pic_Click
Private Sub Pic_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
LoadImage(sender)
End Sub
Private Function IsValidImage(ByVal picpath As String) As Boolean
Try
Dim img As Image = Image.FromFile(picpath)
Return True
Catch ex As Exception
Return False
End Try
End Function
Private Sub LoadImage(ByRef pic As PictureBox)
If IsNothing(pic) Then Exit Sub
Dim o As New OpenFileDialog
If o.ShowDialog = Windows.Forms.DialogResult.OK Then
If IsValidImage(o.FileName) Then
pic.Image = Image.FromFile(o.FileName)
End If
End If
End Sub
and this after edit
Private Function addPictur() As PictureBox
Dim Pic As PictureBox = New PictureBox()
Pic.BorderStyle = BorderStyle.Fixed3D
Pic.BackColor = Color.Coral
Pic.Width = 100
Pic.Height = 100
Pic.Margin = New Padding(5)
Pic.SizeMode = PictureBoxSizeMode.StretchImage
AddHandler Pic.Click, AddressOf Pic_Click' هذي اضافة الحدث المكتوب
Return Pic
End Function