I'm trying to make a scratch card in visual basic 6. I'm wanting to clear any image as the users mouse over it to reveal the image underneath. Is this possible?
Printable View
I'm trying to make a scratch card in visual basic 6. I'm wanting to clear any image as the users mouse over it to reveal the image underneath. Is this possible?
Perhaps someone (with wider skills than me), could translate this into VB6 for you -
https://www.codeproject.com/Tips/104...ol-in-WinForms
Start a new project, add a PictureBox of the size of the picture that you want. Set the AutoRedraw property to True.
Then add another PictureBox, set its Visible property to False, and load into the Picture property the picture that you want.
Then add this code to the form:
Code:Private Sub Picture1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
If Button = 1 Then
On Error Resume Next
Picture1.PaintPicture Picture2.Picture, X - Screen.TwipsPerPixelX * 4, Y - Screen.TwipsPerPixelY * 4, Screen.TwipsPerPixelX * 8, Screen.TwipsPerPixelY * 8, X - Screen.TwipsPerPixelX * 4, Y - Screen.TwipsPerPixelY * 4, Screen.TwipsPerPixelX * 8, Screen.TwipsPerPixelY * 8
End If
End Sub
I have never played with graphics in VB.
Eduardo's solution appears to paint the hidden image onto the visible "mask" image.
If that is all it takes, then we should take our hats off to him for great lateral thinking.
Here is something I came across that may be of interest to some of our members -
http://photodemon.org/
http://photodemon.org/download/
It is VB6 (you can download the EXE, and you can also download the source code)
It is portable (no install required)
It is massive (the qty of Forms, bas files, classes, User Controls)
And it is all free.
It has some transparency as well
HTH someone,
Rob
I just did Eduardo's example. AMAZING!
Rob....your link looks promising
Thx to both
@Sam + Rob, PhotoDemo is created by our fellow member Tanner_H (Tanner Helland)
Here's another take on it, though I may have misunderstood the question:
It paints a grid over a backdrop image and places Image controls on that as "tiles." As the mouse is moved over each visible tile with the left button pressed it makes the Image control invisible.
Not a lot of code here, the attachment is mostly images.Code:Option Explicit
Private Declare Function SetBkColor Lib "gdi32" (ByVal hDC As Long, ByVal crColor As Long) As Long
Private Declare Function ReleaseCapture Lib "user32" () As Long
Private Sub Form_Load()
Dim XSpacing As Single
Dim XPosition As Single
Dim XDrawWidth As Single
Dim YSpacing As Single
Dim YPosition As Single
Dim YDrawWidth As Single
Dim Tile As Integer
XSpacing = ScaleWidth / 5
XDrawWidth = ScaleX(DrawWidth, vbPixels, ScaleMode)
YSpacing = ScaleHeight / 4
YDrawWidth = ScaleY(DrawWidth, vbPixels, ScaleMode)
AutoRedraw = True
FontTransparent = False
ForeColor = vbRed
SetBkColor hDC, vbBlack
DrawStyle = vbDot
For YPosition = YSpacing To ScaleHeight Step YSpacing
Line (0, YPosition)-Step(ScaleWidth, 0)
Next
For XPosition = XSpacing To ScaleWidth Step XSpacing
Line (XPosition, 0)-Step(0, ScaleHeight)
Next
AutoRedraw = False
For YPosition = 0 To ScaleHeight - YSpacing Step YSpacing
For XPosition = 0 To ScaleWidth - XSpacing Step XSpacing
If Tile > 0 Then Load imgTile(Tile)
With imgTile(Tile)
.Move XPosition + XDrawWidth, _
YPosition + YDrawWidth, _
XSpacing - ScaleX(1, vbPixels, ScaleMode), _
YSpacing - ScaleY(1, vbPixels, ScaleMode)
.Visible = True
End With
Tile = Tile + 1
Next
Next
End Sub
Private Sub Form_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
MousePointer = vbDefault
End Sub
Private Sub imgTile_MouseDown(Index As Integer, Button As Integer, Shift As Integer, X As Single, Y As Single)
MousePointer = vbCustom
End Sub
Private Sub imgTile_MouseMove(Index As Integer, Button As Integer, Shift As Integer, X As Single, Y As Single)
If Button = vbLeftButton Then
imgTile(Index).Visible = False
ReleaseCapture
End If
End Sub
Private Sub imgTile_MouseUp(Index As Integer, Button As Integer, Shift As Integer, X As Single, Y As Single)
MousePointer = vbDefault
End Sub
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:
Here's an imageCode: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
Attachment 149205
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
I do not understand your specification ... :confused:
I just wrote that the example you posted is for WinForms (VB.NET) not for VB6.0.
Whether you have reported it before or after Eduardo's post makes no difference.
The point is that this forum is for VB6.0, and it is obvious to those who ask for help in VB6.0.
Otherwise, someone else could post a link to do it in C ++, or in Java, C #, ... and I do not think this is the purpose ...
IMHO, of course.
:wave:
Thank you everyone for your help.