Results 1 to 8 of 8

Thread: form transparency

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Aug 2004
    Posts
    30

    Resolved form transparency

    hey guy can you help in this one close the form and it will slowly disappear
    Last edited by thermo_ll; Feb 21st, 2005 at 08:50 AM.

  2. #2
    Frenzied Member zaza's Avatar
    Join Date
    Apr 2001
    Location
    Borneo Rainforest Habits: Scratching
    Posts
    1,486

    Re: form transparency

    Hi,

    In the Form_Closing event, use e.cancel to stop it. Then activate a timer with suitable interval (e.g. 100) which changes the Opacity property of the form in question to "Opacity - 10". Include a check so that if Opacity <=0 then you can finally close the form. In the Form_Closing event, you'll also want to check the Opacity so that you only do the disappearing act if it hasn't already been done.

    HTH

    zaza

  3. #3
    Hyperactive Member
    Join Date
    Mar 2004
    Location
    Prato - Tuscany - Italy
    Posts
    461

    Re: form transparency

    You have to intercept form's closing event and there you have to decrease form's opacity from 1 to 0, for example in 0.05 step, using a timer....I think!
    Live long and prosper (Mr. Spock)

  4. #4

    Thread Starter
    Junior Member
    Join Date
    Aug 2004
    Posts
    30

    Re: form transparency

    thank you zaza ! that would be a great help another thing , in vb 6 how can i do this ?

  5. #5
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: form transparency

    Here is how you can do form transparency in VB6. This demo uses a slider control
    to adjust the transparency in and out. Windows 2000+ though.

    VB Code:
    1. Option Explicit
    2. 'Add a slider control to the project (Slider1)
    3. Private Declare Function LoadLibrary Lib "kernel32" Alias "LoadLibraryA" _
    4. (ByVal lpLibFileName As String) As Long
    5.  
    6. Private Declare Function GetProcAddress Lib "kernel32" (ByVal hModule As Long, _
    7. ByVal lpProcName As String) As Long
    8.  
    9. Private Declare Function FreeLibrary Lib "kernel32" (ByVal hLibModule As Long) As Long
    10.  
    11. Private Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" _
    12. (ByVal hwnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
    13.  
    14. Private Declare Function SetLayeredWindowAttributes Lib "user32" (ByVal hwnd As Long, _
    15. ByVal crKey As Long, ByVal bAlpha As Byte, ByVal dwFlags As Long) As Long
    16.  
    17. Private Const GWL_EXSTYLE = (-20)
    18. Private Const WS_EX_LAYERED = &H80000
    19. Private Const LWA_ALPHA = &H2
    20.  
    21. Private mlHwnd As Long
    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.     If mlHwnd = 0 Then
    48.         mlHwnd = Me.hwnd
    49.     End If
    50.     AlphaBlendForm mlHwnd, 255 'MAX VALUE = OPAIC/ MIN VALUE = 0 CANT SEE
    51.     Slider1.Value = 255
    52. End Sub
    53.  
    54. Private Sub Slider1_Scroll()
    55.     AlphaBlendForm mlHwnd, Slider1.Value
    56. 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

  6. #6

    Thread Starter
    Junior Member
    Join Date
    Aug 2004
    Posts
    30

    Re: form transparency

    thanks for the help but how do it in closing the form .......i want something like when i close the form it will slowly disappear

    thanks a lot

  7. #7
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: form transparency

    Place a timer on your form and in the timer1_timer event you call the procedure AlphaBlendForm
    passing a variable (which would be dimmed as a static var in the timer procedure)
    decrementing from 255 to 0.
    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

  8. #8

    Thread Starter
    Junior Member
    Join Date
    Aug 2004
    Posts
    30

    Re: form transparency

    thanks for you help guys

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