The Interface
We are sure everybody has played the jigsaw puzzle before, that is to fix the pieces of a picture that were cut into pieces and jumbled up. There are many level of difficulties but eventually you can solve the puzzle. Here we have programmed a simple 3x3 jigsaw puzzle with Visual Basic 6. We programmed it in such a way that you can drag and drop the pieces in the squares that you think are correct. If the piece is correct, it will stay in the correct square otherwise it will not stay there.
The Code
To be able to drag and drop an object, we need to use the DragDrop method.
Dim imgindex As Integer
Dim imgtag As String
Private Sub Image1_DragDrop(Index As Integer, Source As Control, X As Single, Y As Single)
imgtag = Source.Tag
imgindex = Index
Select Case imgindex
Case 0
If imgtag = "11" Then
Image1(0).Picture = Image1(9).Picture
Source.Visible = False
Else
Source.Visible = True
End If
Case 1
If imgtag = "12" Then
Image1(1).Picture = Image1(10).Picture
Source.Visible = False
Else
Source.Visible = True
End If
Case 2
If imgtag = 13 Then
Image1(2).Picture = Image1(11).Picture
Source.Visible = False
Else
Source.Visible = True
End If
Case 3
If imgtag = 21 Then
Image1(3).Picture = Image1(12).Picture
Source.Visible = False
Else
Source.Visible = True
End If
Case 4
If imgtag = 22 Then
Image1(4).Picture = Image1(13).Picture
Source.Visible = False
Else
Source.Visible = True
End If
Case 5
If imgtag = 23 Then
Image1(5).Picture = Image1(14).Picture
Source.Visible = False
Else
Source.Visible = True
End If
Case 6
If imgtag = 31 Then
Image1(6).Picture = Image1(15).Picture
Source.Visible = False
Else
Source.Visible = True
End If
Case 7
If imgtag = 32 Then
Image1(7).Picture = Image1(16).Picture
Source.Visible = False
Else
Source.Visible = True
End If
Case 8
If imgtag = 33 Then
Image1(8).Picture = Image1(17).Picture
Source.Visible = False
Else
Source.Visible = True
End If
End Select
End Sub
Copyright ® 2008 Dr.Liew Voon Kiong . All rights reserved |Contact