|
-
Jul 5th, 2017, 03:03 PM
#13
Re: Scratch card
Piggy-backing on Eduardo and dilletante, here's a refinement.
It utilizes the "PictureBox-in-a-PictureBox" concept.
In design mode, add
1. CommandButton1
2. PB1 .. a PictureBox
3. PB11 .. a PictureBox contained in PB1. Set PB11 Index to 0
Concept
1. Fill PB1 with a .jpg .. the background image
2. Draw grid lines
3. Position (and load) PB11's, fill with a .jpg .. the covering image, the "tiles"
4. Click a "tile", it vanishes, revealing a portion of the background image
5. Click the background image (ie, where a "tile" has vanished), and the lost "tile" reappears.
Here's the code:
Code:
Private Sub Command1_Click()
fpath1 = "d:\scratch1.jpg" ' big .. Arnoutdv .. The Ultimate Cat Thread!
fpath2 = "d:\scratch2.jpg" ' small
zz = 1500
'
PB1.Width = zz * 5
PB1.Height = zz * 4
Set PB1.Picture = LoadPicture(fpath1)
' grid lines
PB1Grid zz
' load tiles
For ii = 0 To 19
With PB11(ii)
If ii > 0 Then
Load PB11(ii)
End If
rr = Int(ii / 5)
.Top = rr * zz
.Left = (ii Mod 5) * zz
.Width = zz
.Height = zz
.Visible = True
Set PB11(ii).Picture = LoadPicture(fpath2)
End With
Next ii
'
End Sub
'
'
Private Sub PB11_Click(ii As Integer)
'
' Make tile "vanish" .. easy, just detect the index ii
' for some reason, the gridline was lost, so call the sub to repaint it
'
PB11(ii).Visible = False
PB1Grid (1500)
'
End Sub
'
'
Private Sub PB1_MouseDown(button As Integer, shift As Integer, x As Single, y As Single)
'
' Make the tile reappear
'
' A little harder, since the "inner" PB11 is not Visible, it is not detected.
' So, we need to figure out "where we are" on the main PB1 and set the PB11 index.
'
zz = 1500
rr = Int(y / zz)
cc = Int(x / zz)
ii = rr * 5 + cc
PB11(ii).Visible = True
'
End Sub
'
'
Private Sub PB1Grid(zz)
'
' horiz grid lines
For ii = 1 To 3
xx1 = 0
xx2 = zz * 5
yy1 = ii * zz
yy2 = yy1
PB1.Line (xx1, yy1)-(xx2, yy2), vbWhite
Next ii
' vert grid lines
For ii = 1 To 4
xx1 = ii * zz
xx2 = xx1
yy1 = 0
yy2 = zz * 4
PB1.Line (xx1, yy1)-(xx2, yy2), vbWhite
Next ii
'
End Sub
Here's an image

Credits:
dilletante .. I stole your "tile"
Arnoutdv .. I stole your background image.
BTW, Arno's full pic can be seen in this Chit/Chat Forum thread .. it's a gas.
http://www.vbforums.com/showthread.p...te-Cat-Thread!
Spoo
Last edited by Spooman; Jul 5th, 2017 at 03:51 PM.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|