Wednesday, January 19, 2011

Windows Blend Effect


Public Class Form1
    Private Const AW_BLEND = &H80000
    Private Declare Function AnimateWindow Lib "user32" (ByVal hwnd As Int32, ByVal dwTime As Int32, ByVal dwFlags As Int32) As Boolean
    Dim winHide As Integer = &H10000
    Dim winBlend As Integer = &H80000
    Private Sub Form1_FormClosing(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
        Try
            AnimateWindow(Me.Handle.ToInt32, CInt(500), winHide Or winBlend)
        Catch ex As Exception
        End Try

    End Sub

'You can also use Timer control for blend effect as loading/closing event
'If you are using for load event:
    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Timer1.Enabled = True
        Me.Opacity = 0.1
        'Me.FormBorderStyle = Windows.Forms.FormBorderStyle.None
    End Sub

    Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
        Me.Opacity = Me.Opacity + 0.1
        If Me.Opacity = 1 Then
            Timer1.Enabled = False
        End If
    End Sub

'If you are using for closing event then set Me.Opacity = 1 in form load event and 'in Timer_Tick event change Me.Opacity = Me.Opacity - 0.1 with Me.Opacity = 'Me.Opacity + 0.1 also change If - End If Statement with If Me.Opacity = 0.1 Then
'Happy Coding...

No comments:

Post a Comment