Results 1 to 16 of 16

Thread: Scratch card

  1. #1

    Thread Starter
    Member
    Join Date
    Feb 2005
    Posts
    51

    Question Scratch card

    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?

  2. #2
    Frenzied Member
    Join Date
    Dec 2008
    Location
    Melbourne Australia
    Posts
    1,487

    Re: Scratch card

    Perhaps someone (with wider skills than me), could translate this into VB6 for you -
    https://www.codeproject.com/Tips/104...ol-in-WinForms

  3. #3
    PowerPoster
    Join Date
    Feb 2017
    Posts
    5,700

    Re: Scratch card

    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

  4. #4
    Frenzied Member
    Join Date
    Dec 2008
    Location
    Melbourne Australia
    Posts
    1,487

    Re: Scratch card

    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
    Last edited by Bobbles; Jul 5th, 2017 at 03:43 AM.

  5. #5
    PowerPoster SamOscarBrown's Avatar
    Join Date
    Aug 2012
    Location
    NC, USA
    Posts
    9,624

    Re: Scratch card

    I just did Eduardo's example. AMAZING!

    Rob....your link looks promising

    Thx to both

  6. #6
    PowerPoster Arnoutdv's Avatar
    Join Date
    Oct 2013
    Posts
    6,746

    Re: Scratch card

    @Sam + Rob, PhotoDemo is created by our fellow member Tanner_H (Tanner Helland)

  7. #7
    PowerPoster dilettante's Avatar
    Join Date
    Feb 2006
    Posts
    24,487

    Re: Scratch card

    Here's another take on it, though I may have misunderstood the question:

    Name:  sshot.png
Views: 404
Size:  33.1 KB

    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.

    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
    Not a lot of code here, the attachment is mostly images.
    Attached Files Attached Files

  8. #8
    gibra
    Guest

    Re: Scratch card

    Quote Originally Posted by Bobbles View Post
    Perhaps someone (with wider skills than me), could translate this into VB6 for you -
    https://www.codeproject.com/Tips/104...ol-in-WinForms
    This sample is for WinForms (VB.NET) not for VB6.0...

  9. #9
    gibra
    Guest

    Re: Scratch card

    Quote Originally Posted by Eduardo- View Post
    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
    Perfect!!!

  10. #10
    PowerPoster Arnoutdv's Avatar
    Join Date
    Oct 2013
    Posts
    6,746

    Re: Scratch card

    Quote Originally Posted by gibra View Post
    This sample is for WinForms (VB.NET) not for VB6.0...
    Hence the remark that the project needs to be translated

  11. #11
    Fanatic Member Spooman's Avatar
    Join Date
    Mar 2017
    Posts
    868

    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

    Name:  scratch3.png
Views: 381
Size:  157.0 KB

    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.

  12. #12
    gibra
    Guest

    Re: Scratch card

    Quote Originally Posted by Arnoutdv View Post
    Hence the remark that the project needs to be translated
    Doesn't needs any translation from WinForms sample, because the code snippet posted by Eduardo is more than enough.
    See image.
    Attached Images Attached Images  
    Last edited by gibra; Jul 6th, 2017 at 02:13 AM.

  13. #13
    Frenzied Member
    Join Date
    Dec 2008
    Location
    Melbourne Australia
    Posts
    1,487

    Re: Scratch card

    Quote Originally Posted by gibra View Post
    Doesn't needs any translation, because the code snippet posted by Eduardo is more than enough.

    I do not understand why complicating simple things.
    When I made the post, Eduardo had not posted his simple solution

  14. #14
    gibra
    Guest

    Re: Scratch card

    Quote Originally Posted by Bobbles View Post
    When I made the post, Eduardo had not posted his simple solution
    I do not understand your specification ...
    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.

  15. #15
    Fanatic Member Spooman's Avatar
    Join Date
    Mar 2017
    Posts
    868

    Re: Scratch card

    Quote Originally Posted by gibra View Post
    ,,, because the code snippet posted by Eduardo is more than enough.
    See image.
    Thanks for your images.

    I had not fully appreciated the power of Eduardo's post until I saw your images, and then tried his code.
    He truly captured the "scratch" effect.

    Spoo
    Last edited by Spooman; Jul 6th, 2017 at 06:43 AM.

  16. #16

    Thread Starter
    Member
    Join Date
    Feb 2005
    Posts
    51

    Re: Scratch card

    Thank you everyone for your help.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width