Results 1 to 2 of 2

Thread: Having difficulties on fading in/out of the child form..

  1. #1

    Thread Starter
    Fanatic Member louvelle's Avatar
    Join Date
    Jun 2008
    Posts
    513

    Having difficulties on fading in/out of the child form..

    Based on this thread:

    http://www.vbforums.com/showthread.p...ight=fade+form

    I would like to ask how to fade a child form from the parent form?

    Either both the parent and the child form fades in and out or the parent only fades in when I tried it.

    Manny Pacquiao once posted in his twitter:
    It doesn't matter if the grammar is wrong, what matter is that you get the message

  2. #2
    PowerPoster RhinoBull's Avatar
    Join Date
    Mar 2004
    Location
    New Amsterdam
    Posts
    24,132

    Re: Having difficulties on fading in/out of the child form..

    Always helpful to show your actual code... Anyways, you can use timer on the main form.

    Here is scenario I did in my sample:
    - form1 is the main form
    - form2 is a child form
    - you load form2 and at some point need to unload it
    - form2 would first fade out and then gets unloaded
    Code:
    'all code belongs in form1:
    Option Explicit
    
    Private Declare Function GetWindowLong Lib "user32" Alias "GetWindowLongA" _
        (ByVal hwnd As Long, ByVal nIndex As Long) As Long
    
    Private Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" _
        (ByVal hwnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
    
    Private Declare Function SetLayeredWindowAttributes Lib "user32" _
        (ByVal hwnd As Long, ByVal crey As Byte, ByVal bAlpha As Byte, ByVal dwFlags As Long) As Long
    
    Private Const GWL_EXSTYLE = (-20)
    Private Const WS_EX_LAYERED = &H80000
    Private Const LWA_ALPHA = &H2&
    
    Dim bt As Byte
    
    Private Sub MakeItTransparent(frm As Form, Opacity As Byte)
        Call SetWindowLong(frm.hWnd, GWL_EXSTYLE, GetWindowLong(frm.hWnd, GWL_EXSTYLE) Or WS_EX_LAYERED)
        Call SetLayeredWindowAttributes(frm.hwnd, 0, Opacity, LWA_ALPHA)
    End Sub
    
    Private Sub Command1_Click()
        Form2.Show , Me
    End Sub
    
    Private Sub Command2_Click()
        bt = 255
        Timer1.Interval = 10
        Timer1.Enabled = True
    End Sub
    
    Private Sub Timer1_Timer()
        bt = bt - 1
        If bt = 0 Then
            Timer1.Enabled = False
            Unload Form2
            Exit Sub
        End If
        MakeItTransparent Form2, bt
    End Sub

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