Public Class frmEffect
Dim img As Bitmap
Dim frmLocation As Point
Dim originalCentre As Point
Public Sub New(ByVal bgImage As Bitmap, ByVal frmBounds As Rectangle)
' This call is required by the Windows Form Designer.
InitializeComponent()
' Add any initialization after the InitializeComponent() call.
img = bgImage
Me.BackgroundImage = bgImage
Me.Bounds = frmBounds
frmLocation = Me.Location
originalCentre = New Point(Me.Width \ 2, Me.Height \ 2)
Me.DoubleBuffered = True
End Sub
''' <summary>
''' rotation timer
''' </summary>
''' <param name="sender"></param>
''' <param name="e"></param>
''' <remarks>interval = 20</remarks>
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
Static angle As Integer = 0
If angle = 360 Then Timer1.Enabled = False : Me.BackgroundImageLayout = ImageLayout.Stretch : Timer2.Enabled = True : Return
angle += 2
Me.BackgroundImage = Nothing
' Copy the output bitmap from the source image.
Dim bm_in As New Bitmap(img)
' Make an array of points defining the
' image's corners.
Dim wid As Single = bm_in.Width
Dim hgt As Single = bm_in.Height
Dim corners As Point() = { _
New Point(0, 0), _
New Point(CInt(wid), 0), _
New Point(0, CInt(hgt)), _
New Point(CInt(wid), CInt(hgt))}
' Translate to center the bounding box at the origin.
Dim cx As Integer = CInt(wid / 2)
Dim cy As Integer = CInt(hgt / 2)
For i As Integer = 0 To 3
corners(i).X -= cx
corners(i).Y -= cy
Next i
' Rotate.
Dim theta As Single = CSng(angle * Math.PI _
/ 180.0)
Dim sin_theta As Single = CSng(Math.Sin(theta))
Dim cos_theta As Single = CSng(Math.Cos(theta))
Dim X As Single
Dim Y As Single
For i As Integer = 0 To 3
X = corners(i).X
Y = corners(i).Y
corners(i).X = CInt(X * cos_theta + Y * sin_theta)
corners(i).Y = CInt(-X * sin_theta + Y * cos_theta)
Next i
' Translate so X >= 0 and Y >=0 for all corners.
Dim xmin As Integer = corners(0).X
Dim ymin As Integer = corners(0).Y
For i As Integer = 1 To 3
If xmin > corners(i).X Then xmin = corners(i).X
If ymin > corners(i).Y Then ymin = corners(i).Y
Next i
For i As Integer = 0 To 3
corners(i).X -= xmin
corners(i).Y -= ymin
Next i
' Create an output Bitmap and Graphics object.
Dim bm_out As New Bitmap(CInt(-2 * xmin), CInt(-2 * _
ymin))
Dim gr_out As Graphics = Graphics.FromImage(bm_out)
Dim p() As Point = {corners(3), corners(2)}
' Drop the last corner lest we confuse DrawImage,
' which expects an array of three corners.
ReDim Preserve corners(2)
' Draw the result onto the output Bitmap.
gr_out.DrawImage(bm_in, corners)
ReDim Preserve corners(3)
corners(3) = p(1)
corners(2) = p(0)
Dim path As New Drawing.Drawing2D.GraphicsPath
path.AddPolygon(corners)
Dim newCentre As New Point(Rectangle.Round(path.GetBounds).Size.Width \ 2, Rectangle.Round(path.GetBounds).Size.Height \ 2)
Dim l As Point = frmLocation
l.Offset(originalCentre.X - newCentre.X, originalCentre.Y - newCentre.Y)
Me.Bounds = New Rectangle(l, Rectangle.Round(path.GetBounds).Size)
Me.Region = New Region(path)
Me.BackgroundImage = bm_out
Application.DoEvents()
End Sub
''' <summary>
''' shrink timer
''' </summary>
''' <param name="sender"></param>
''' <param name="e"></param>
''' <remarks>interval = 25</remarks>
Private Sub Timer2_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer2.Tick
Dim r As Rectangle = Me.Bounds
If Me.Width > 10 And Me.Height > 10 Then
r.Inflate(-10, -10)
Me.Bounds = r
Else
Me.Close()
'load your new form here
End If
End Sub
End Class