Skip to content

Instantly share code, notes, and snippets.

@aethur
Created May 14, 2009 08:50
Show Gist options
  • Select an option

  • Save aethur/111571 to your computer and use it in GitHub Desktop.

Select an option

Save aethur/111571 to your computer and use it in GitHub Desktop.
Public Module FadeEffect
Public Class FadeControl
Friend WithEvents Timer As New Timer()
Private Bound As Rectangle
Private BoundReal As Rectangle
Private BoundSmall As Rectangle
Private CForm As Form
Private Center As Point
Private Show As Boolean = False
Public Sub New(ByVal MForm As Form)
CForm = MForm
Bound = CForm.Bounds
BoundReal = Bound
BoundSmall = Bound
BoundSmall.Width -= 40
BoundSmall.X += 20
BoundSmall.Height -= 40
BoundSmall.Y += 20
Center = New Point(Bound.Width / 2 + Bound.X, Bound.Height / 2 + Bound.Y)
Timer.Interval = 20
End Sub
Public Sub ShowForm()
CForm.Opacity = 0
BoundSmall.X = Center.X - BoundSmall.Width / 2
BoundSmall.Y = Center.Y - BoundSmall.Height / 2
CForm.Bounds = BoundSmall
CForm.Visible = True
Timer.Enabled = True
Timer.Start()
Show = True
End Sub
Public Sub HideForm()
Timer.Enabled = True
Timer.Start()
Show = False
End Sub
Public Event Hided(ByVal sender As Object)
Public Event Shown(ByVal sender As Object)
Private Sub EventHandle(ByVal s As Object, ByVal e As EventArgs) Handles Timer.Tick
Center = New Point(CForm.Width / 2 + CForm.Location.X, CForm.Height / 2 + CForm.Location.Y)
If Show Then
CForm.Opacity -= (CForm.Opacity - 1) / 6
Bound.Width -= (Bound.Width - BoundReal.Width) / 5
Bound.Height -= (Bound.Height - BoundReal.Height) / 5
Bound.X = Center.X - Bound.Width / 2
Bound.Y = Center.Y - Bound.Height / 2
CForm.Bounds = Bound
If CForm.Opacity >= 0.99 Then
CForm.Opacity = 1
CForm.Visible = True
Timer.Stop()
RaiseEvent Shown(Me)
End If
Else
CForm.Opacity -= (CForm.Opacity) / 6
Bound.Width -= (Bound.Width - BoundSmall.Width) / 5
Bound.Height -= (Bound.Height - BoundSmall.Height) / 5
Bound.X = Center.X - Bound.Width / 2
Bound.Y = Center.Y - Bound.Height / 2
CForm.Bounds = Bound
If CForm.Opacity <= 0.01 Then
CForm.Opacity = 0
CForm.Visible = False
Timer.Stop()
RaiseEvent Hided(Me)
End If
End If
End Sub
End Class
End Module
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment