Userform FadeIn/FadeOut Ivan F Moala, read in please

merlin_the_magician

Active Member
Joined
Jul 31, 2002
Messages
480
Ivan,

first of all i have to thank you for sending me an example workbook on fading userforms. It's lovely, exactly what i meant.
I have been playing with it a little, but i think i will need a lity little bit of help.
I cut parts of you code, and pasted them together like the code underneath. It seems to be working fine at first, but then it somehow gets stuck on the last piece of the code, Private Function MakeTransparent(lIndex As Long) As Long what is wrong?


Private Sub UserForm_Activate()
'// Main routine to FadeIn/FadeOut
Application.Wait (Now + TimeValue("0:00:03"))
Call FadeOut(256 * 4)
Image1.Visible = False
Me.BackColor = &H8000000F
Call FadeIn(256 * 4)
Application.Wait (Now + TimeValue("0:00:06"))
Unload Me
End Sub



' MODIFIED: Ivan F Moala 2/6/2002
Private Sub UserForm_DblClick(ByVal Cancel As MSForms.ReturnBoolean)
'// Leave this here as your backdoor, incase you have NO CLOSE BUTTON
Unload Me
End Sub

''//
Private Function ShowTitleBar(ByVal bState As Boolean)
Dim lStyle As Long
Dim tR As RECT

'// Get the window's position:
GetWindowRect lFrmHdl, tR

'// Modify whether title bar will be visible:
lStyle = GetWindowLong(lFrmHdl, GWL_STYLE)
'
If Not bState Then
lStyle = lStyle And Not WS_SYSMENU
lStyle = lStyle And Not WS_MAXIMIZEBOX
lStyle = lStyle And Not WS_MINIMIZEBOX
lStyle = lStyle And Not WS_CAPTION
blnTitleVisible = True
Else
lStyle = lStyle Or WS_SYSMENU
lStyle = lStyle Or WS_MAXIMIZEBOX
lStyle = lStyle Or WS_MINIMIZEBOX
lStyle = lStyle Or WS_CAPTION
blnTitleVisible = False
End If

SetWindowLong lFrmHdl, GWL_STYLE, lStyle

'// Ensure the style takes and make the window the
'// same size, regardless that the title bar
'// is now a different size:
SetWindowPos lFrmHdl, 0, tR.Left, tR.Top, tR.Right - tR.Left, tR.Bottom - tR.Top, _
SWP_NOREPOSITION Or SWP_NOZORDER Or SWP_FRAMECHANGED
Me.Repaint

End Function

Private Sub FadeIn(Fin As Long)
Dim X As Long

MakeTransparent 0

X = 0
Do Until X = Fin
DoEvents
X = X + 1
MakeTransparent X / 2
Loop

End Sub

Private Function FadeOut(Fin As Long)
Dim Y As Long

Call MakeTransparent(255)

Y = Fin '1000

Do Until Y = 0
DoEvents
Y = Y - 1
Call MakeTransparent(Y / 2)
Loop

End Function

Private Function MakeTransparent(lIndex As Long) As Long

End Function

On Error Resume Next
If lIndex < 0 Or lIndex > 255 Then
MakeTransparent = 0 '1
Else
lResult = GetWindowLong(lFrmHdl, GWL_EXSTYLE)
lResult = lResult Or WS_EX_LAYERED
SetWindowLong lFrmHdl, GWL_EXSTYLE, lResult
SetLayeredWindowAttributes lFrmHdl, 0, lIndex, LWA_ALPHA
MakeTransparent = 0
End If

If Err Then MakeTransparent = 2

End Function
 
Allright, one more question and I will stop bugging you with this…
In order adjust the time, used to FadeIn or FadeOut the Userform, I changed the X=X+1 value in the “Private Sub FadeIn(Fin As Long)” code to into X=X+10

This however seems to affect the Unload Me command in the “Private Sub UserForm_Activate()” code, since the form does not unload, unless double clicked. Why is that, should some other value change as well?

(yes, I know… i´m messing around…)
 
Upvote 0

Excel Facts

Easy bullets in Excel
If you have a numeric keypad, press Alt+7 on numeric keypad to type a bullet in Excel.
change to

Code:
Private Sub UserForm_Activate()
'// Main routine to FadeIn/FadeOut
Application.Wait (Now + TimeValue("0:00:03"))
Call FadeOut(1000)
Call FadeIn(1000)
Application.Wait (Now + TimeValue("0:00:06"))
Unload Me
End Sub

ie multiple of 10
 
Upvote 0

Forum statistics

Threads
1,215,143
Messages
6,123,277
Members
449,093
Latest member
Vincent Khandagale

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top