Thank you for visiting → Compete For Nothing.com ← If you find anything useful leave me a comment and share. Interested in Arduino, C#, Unity3D, Game Creation, VB.NET, learning and most important of all Sharing!.
Close Notification
Open Notification

VB.NET 2010 Perfect Fade Out Windows Form Using WINAPI

VB.NET 2010 Perfect Fade Out Windows Form Using WINAPI

Download FadeOut Project File

First we need a timer called tmrExit with interval set as 2000. We will use this timer to exit the application.

Public Class Form1
    Private Declare Function AnimateWindow Lib "user32" (ByVal hwnd As Integer, ByVal dwtime As Integer, ByVal dwflags As Integer) As Boolean

    Private Sub btnFade_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnFade.Click
        AnimateWindow(Me.Handle, 600, &H80000 Or &H10000)
        tmrExit.Enabled = True
    End Sub

    Private Sub tmrExit_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles tmrExit.Tick
        Application.Exit()
    End Sub
End Class

Some More Info

WINAPI

The Me.Handle is the windows hwnd for this form. This tells the API
which form, control to apply the animation to.

The 600 is the time it takes for the animation in milliseconds. 1 
second is 1000 miliseconds. Adjust this value for faster or slower 
animations.

The last two values are or'd together and can be any of the following:

&O1 = Animate the window from left to right. This flag can be used 
with roll or slid eanimation It is ignored when used with the &H10 
flag.

&H2 = Animate the window from right to left. This flag can be used 
with roll or slide animation. It is ignored when used with the &H10 
flag.

&H4 = Animate the window from top to bottom. This flag can be used 
with roll or slide animation. It is ignored when used with the &H10
flag.

&H8 = Animate the window from bottom to top. This flag can be used 
with roll or slide animation. It is ignored when used with the &H10
flag.

&H10 = Makes the window appear to collapse inward if the &H10000 flag
is used or expand outward if the &H10000 flag is not used.

&H10000 = Hides the window. By default, the window is shown.

&H20000 = Activates the window. Do not use this flag with &H10000.

&H40000 = Uses slide animation. By default, roll animation is used. 
This flag is ignored when used with the &H10 flag.

&H80000 = Uses a fade effect. This flag can be used only if hwnd is a 
top-level window.

Leave a reply