Results 1 to 1 of 1

Thread: Fade Picture in Picturebox from One Picture to Another

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Sep 2013
    Posts
    190

    Fade Picture in Picturebox from One Picture to Another

    'Need 2 pictureboxes (Picture1 & Picture2)
    'Set both pictureboxes AutoRedraw to True
    'Set both pictureboxes ScaleMode to vbPixels
    'Paste the following code in the Decs
    Code:
    Private Const AC_SRC_OVER = &H0
    
    Private Type BLENDFUNCTION
        BlendOp As Byte
        BlendFlags As Byte
        SourceConstantAlpha As Byte
        AlphaFormat As Byte
    End Type
    
    Private Declare Function AlphaBlend Lib "msimg32.dll" (ByVal hdc As Long, ByVal lInt As Long, ByVal lInt As Long, ByVal lInt As Long, ByVal lInt As Long, ByVal hdc As Long, ByVal lInt As Long, ByVal lInt As Long, ByVal lInt As Long, ByVal lInt As Long, ByVal BLENDFUNCT As Long) As Long
    Private Declare Sub RtlMoveMemory Lib "kernel32.dll" (Destination As Any, Source As Any, ByVal Length As Long)
    Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
    Private BF As BLENDFUNCTION, lBF As Long, fade As Byte
    Private FadeInProgress As Boolean
    
    Public Function FadeThePicture(fromPicture As PictureBox, toPicture As PictureBox)
    If FadeInProgress Then Exit Function
    
    For fade = 1 To 60 Step 2
        With BF
            .BlendOp = AC_SRC_OVER
            .BlendFlags = 0
            .SourceConstantAlpha = fade
            .AlphaFormat = 0
        End With
        RtlMoveMemory lBF, BF, 4
        AlphaBlend toPicture.hdc, 0, 0, toPicture.ScaleWidth, toPicture.ScaleHeight, fromPicture.hdc, 0, 0, fromPicture.ScaleWidth, fromPicture.ScaleHeight, lBF
        toPicture.Refresh
        Sleep 25
    Next fade
    
    DoEvents
    End Function
    Last edited by si_the_geek; Dec 1st, 2013 at 08:31 AM. Reason: Added Code Tags

Tags for this Thread

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