Skip to content

Instantly share code, notes, and snippets.

@nissuk
Created October 6, 2010 15:02
Show Gist options
  • Save nissuk/613488 to your computer and use it in GitHub Desktop.
Save nissuk/613488 to your computer and use it in GitHub Desktop.
Public Class Form
Sub New()
InitializeComponent()
End Sub
Protected Overrides Sub OnVisibleChanged(ByVal e As System.EventArgs)
If Me.Visible Then Me.FadeIn() Else Me.FadeOut()
MyBase.OnVisibleChanged(e)
End Sub
Protected Overrides Sub OnFormClosed(ByVal e As System.Windows.Forms.FormClosedEventArgs)
Me.FadeOut()
MyBase.OnFormClosed(e)
End Sub
Protected Sub FadeIn()
Dim msec As Integer = 200
Dim animateFlags As Win32.AnimateWindowFlags = _
Win32.AnimateWindowFlags.AW_ACTIVATE Or Win32.AnimateWindowFlags.AW_BLEND
Win32.AnimateWindow(Me.Handle, msec, animateFlags)
End Sub
Protected Sub FadeOut()
Dim msec As Integer = 200
Dim animateFlags As Win32.AnimateWindowFlags = _
Win32.AnimateWindowFlags.AW_HIDE Or Win32.AnimateWindowFlags.AW_BLEND
Win32.AnimateWindow(Me.Handle, msec, animateFlags)
End Sub
End Class
Imports System.Runtime.InteropServices
Partial Public Class Win32
''' <remarks>http://www.pinvoke.net/default.aspx/Enums/AnimateWindowFlags.html</remarks>
<Flags()> _
Public Enum AnimateWindowFlags
AW_HOR_POSITIVE = &H1
AW_HOR_NEGATIVE = &H2
AW_VER_POSITIVE = &H4
AW_VER_NEGATIVE = &H8
AW_CENTER = &H10
AW_HIDE = &H10000
AW_ACTIVATE = &H20000
AW_SLIDE = &H40000
AW_BLEND = &H80000
End Enum
''' <remarks>http://pinvoke.net/default.aspx/user32/AnimateWindow.html</remarks>
<DllImport("user32.dll")> _
Public Shared Function AnimateWindow(ByVal hwnd As IntPtr, ByVal time As Integer, ByVal flags As AnimateWindowFlags) As Boolean
End Function
End Class
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment