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.
Printable View
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.
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