Actually your code looks very neat, well done.
The obvious areas is the one mentioned where you have long expressions excluding various components;
كود:
If Not target.Equals(Pic1) AndAlso Not target.Equals(Pic2) AndAlso Not target.Equals(Pic3) AndAlso Not target.Equals(Pic4) AndAlso Not target.Equals(Pic5) AndAlso Not target.Equals(Pic6) AndAlso Not target.Equals(Pic7) AndAlso Not target.Equals(Pic8) AndAlso Not target.Equals(Pic9) AndAlso Not target.Equals(Pic10) AndAlso Not target.Equals(Pic11) AndAlso Not target.Equals(Pic12) AndAlso Not target.Equals(Pic13) AndAlso Not target.Equals(Pic14) AndAlso Not target.Equals(Pic15) AndAlso Not target.Equals(Pic16) AndAlso Not target.Equals(Pic17) AndAlso Not target.Equals(Pic18) AndAlso Not target.Equals(Pic19) AndAlso Not target.Equals(Pic20) Then
Since you have Pic1 to Pic20 and you want to exclude all of them you could do something like;
كود:
If target.Name.Length <= 3 OR _
(target.Name.Length > 3 AndAlso target.Name.Substring(0,3) <> "Pic") Then
I also notice you do this
كود:
If target.Name = "Pic1" OR ..... Then
s = True
Else
s = False
End If
If s Then
pic.Visible = False
End If
where you could just do this;
كود:
s = target.Name = "Pic1" OR .....
pic.Visible = NOT s
Call me anal but I always like to see variables initialized;
كود:
Dim j As Integer = 0
Dim k As String = String.Empty
and to be even more anal, I also like to see variable names that are meaningful, even though it's more typing;
كود:
Dim NumberOfPictures As Integer = 0
You can also tidy some code by doing;
كود:
'In situations like this
Pic10.Visible = True
Pic10.AllowDrop = True
Pic10.Enabled = True
'Doing this instead
With Pic10
.Visible = True
.AllowDrop = True
.Enabled = True
End With
You can get rid of the event code by creating the PictureBoxes programatically, so for example;
كود:
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) _
Handles MyBase.Load
Dim Pic(10) As PictureBox
For i As Integer = 0 To Pic.GetUpperBound(0)
Pic(i) = New PictureBox
'Add the box to the form
Me.Controls.Add(Pic(i))
'Position each box to the right of the previous
If i > 0 Then Pic(i).Left = Pic(i - 1).Right + 10
With Pic(i)
'Set the borderstyle
.BorderStyle = BorderStyle.FixedSingle
'Give the instance a name
.Name = "Pic" & i.ToString
'Add a handler to invoke on the relevant event
End With
AddHandler Pic(i).Click, AddressOf PictureBoxHandler
Next
End Sub
Private Sub PictureBoxHandler(ByVal sender As System.Object, ByVal e As System.EventArgs)
'Will handle all Pic boxes
MessageBox.Show(CType(sender, PictureBox).Name.ToString)
End Sub
Hope these comments help, as I mentioned at the beginning, your code is pretty good.
_____________________________
http://www.vbforums.com/showthread.php?t=468342