Results 1 to 3 of 3

Thread: Can I make a picture appear gradually?

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Feb 2000
    Location
    the UK
    Posts
    265

    Can I make a picture appear gradually?

    I would like to have a picture appear gradually (like a fade)

    I thought something like this might work:

    Code:
    picAdvert.Width = 0
    Dim i As Integer
    For i = 1 To picAdvert.Width
    
    picAdvert.Width = i
    Next
    crappy code I know - but should this work?

    SImon

  2. #2
    Hyperactive Member
    Join Date
    Apr 2002
    Location
    UK
    Posts
    506
    You've got the right idea but that would be more of a scroll than a fade and on higher end computers it would happen so fast you wouldn't even see it, add a sleep call of 5ms or something.

    Also you set the width of the picturebox to 1 at the start, preventing it from working. The for loop starts the i var off at one so you don't need to do it.
    Last edited by adzzzz; Jul 20th, 2004 at 02:16 PM.

  3. #3
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709
    Here is an example of fading a form using a slider control. I know
    you can change it to the picturebox, but only works on Windows 2K +.

    VB Code:
    1. Option Explicit
    2. 'CONTROLS:
    3. '1 Slider (Slider1)
    4. 'Microsoft Windows Common Controls 6.0 (SP 5 or SP 6)
    5. Private Declare Function LoadLibrary Lib "kernel32" Alias "LoadLibraryA" _
    6. (ByVal lpLibFileName As String) As Long
    7.  
    8. Private Declare Function GetProcAddress Lib "kernel32" (ByVal hModule As Long, _
    9. ByVal lpProcName As String) As Long
    10.  
    11. Private Declare Function FreeLibrary Lib "kernel32" (ByVal hLibModule As Long) As Long
    12.  
    13. Private Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" _
    14. (ByVal hwnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
    15.  
    16. Private Declare Function SetLayeredWindowAttributes Lib "user32" (ByVal hwnd As Long, _
    17. ByVal crKey As Long, ByVal bAlpha As Byte, ByVal dwFlags As Long) As Long
    18.  
    19. Private Const GWL_EXSTYLE = (-20)
    20. Private Const WS_EX_LAYERED = &H80000
    21. Private Const LWA_ALPHA = &H2
    22.  
    23. Public Sub AlphaBlendForm(ByVal lHwnd As Long, ByVal intTranslucenceLevel As Integer)
    24.     If APIExists("SetLayeredWindowAttributes", "User32") Then
    25.         SetWindowLong lHwnd, GWL_EXSTYLE, WS_EX_LAYERED
    26.         SetLayeredWindowAttributes lHwnd, 0, intTranslucenceLevel, LWA_ALPHA
    27.     Else
    28.         MsgBox "Your OS does not support Alpha Blending.", vbExclamation, "Alpha Blend"
    29.     End If
    30. End Sub
    31.  
    32. Public Function APIExists(ByVal pstrFunctionName As String, ByVal pstrDllName As String) As Boolean
    33.     Dim lngHandle   As Long
    34.     Dim lngAddr     As Long
    35.     lngHandle = LoadLibrary(pstrDllName)
    36.     If Not (lngHandle = 0) Then
    37.         lngAddr = GetProcAddress(lngHandle, pstrFunctionName)
    38.         FreeLibrary lngHandle
    39.     End If
    40.     APIExists = Not (lngAddr = 0)
    41. End Function
    42.  
    43. Private Sub Form_Load()
    44.     Slider1.Max = 255
    45.     Slider1.Min = 10
    46.     Slider1.LargeChange = 5
    47.     AlphaBlendForm Me.hwnd, 255 'MAX VALUE = OPAIC/ MIN VALUE = 0 CAN'T SEE
    48.     Slider1.Value = 255
    49. End Sub
    50.  
    51. Private Sub Slider1_Scroll()
    52.     AlphaBlendForm Me.hwnd, Slider1.Value
    53. End Sub
    HTH
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

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