I guess everybody has played with jigsaw puzzle before, that is to fix the pieces of a picture that are jumbled up. There are many level of difficulties but usually you can eventually solve the puzzle. Here I have programmed a simple 3x3 jigsaw puzzle with Visual Basic. I programmed it in such a way that you can drag and drop the pieces in the squares that you think are correct. However, if it is now a correct place, the piece just would not stay there.
To be able to drag and drop an object, we need to use the DragDrop method. I would like to explain the codes today but while not take a while to understand it yourself and let me explain more in detail one week later, is that OK?
The Interface
The Codes
Dim imgindex As Integer
Dim imgtag As String
Private Sub Form_Load()
End Sub
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