Holiday Animation
From this holiday card design, featured here: http://www.hazlingerartist.com/2025/11/featured-traditionalsubject-artworks.html
Code:
I struggled previously with layering labels, as PNGs that I would add would not preserve their transparency. If you use Label.Controls.Add and add each label that way (in combination with Label.Invalidate so it loops properly) the transparency is preserved. This is a great way to avoid using the Paint sub if you're making a basic timer animation, like the twinkling star here. I did need to use Paint for the array of snow.
Happy holidays, and here's to a great 2026!
Public Class Form1
Dim tickCount As Integer = 0
Dim star1Ticks As Integer = 0
Dim star2Ticks As Integer = 1
Dim star3Ticks As Integer = 3
Dim star4Ticks As Integer = 4
Private snowLarge() As Image
Private snowSmall() As Image
Private snowLargeXPos() As Single
Private snowLargeYPos() As Single
Private snowSmallXPos() As Single
Private snowSmallYPos() As Single
Private snowLargeSpeed() As Single
Private snowSmallSpeed() As Single
Private curveSlowerDowner() As Single
Private frameCount As Single = 60
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Timer1.Enabled = True
Timer2.Enabled = True
Timer1.Interval = 400
Timer2.Interval = 33
Timer1.Start()
Timer2.Start()
Label1.Controls.Add(Label2)
Label1.Controls.Add(Label3)
Label1.Controls.Add(Label4)
Label1.Controls.Add(Label5)
Label1.Controls.Add(Label6)
Label1.Controls.Add(Label7)
ReDim snowLarge(30)
ReDim snowSmall(50)
ReDim snowLargeXPos(30)
ReDim snowLargeYPos(30)
ReDim snowSmallXPos(50)
ReDim snowSmallYPos(50)
ReDim snowLargeSpeed(30)
ReDim snowSmallSpeed(50)
ReDim curveSlowerDowner(50)
For n = 0 To 29
snowLargeXPos(n) = 592 * Rnd()
snowLargeYPos(n) = 0
snowLargeSpeed(n) = 2 * Rnd() + 1
curveSlowerDowner(n) = (51 * Rnd() + 25)
snowLarge(n) = My.Resources.snow_large
Next
For v = 0 To 49
snowSmallXPos(v) = 592 * Rnd()
snowSmallYPos(v) = 0
snowSmallSpeed(v) = 2 * Rnd() + 1
curveSlowerDowner(v) = (51 * Rnd() + 25)
snowSmall(v) = My.Resources.snow_small
Next
End Sub
Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick
Label1.Invalidate()
Label2.Invalidate()
Label3.Invalidate()
Label4.Invalidate()
Label5.Invalidate()
tickCount += 1
If tickCount >= star1Ticks Then
Label3.Hide()
Label4.Hide()
Label5.Hide()
End If
If tickCount >= star2Ticks Then
Label3.Show()
Label2.Hide()
Label4.Hide()
Label5.Hide()
End If
If tickCount >= star3Ticks Then
Label2.Hide()
Label3.Hide()
Label4.Show()
Label5.Hide()
End If
If tickCount >= star4Ticks Then
Label2.Hide()
Label3.Hide()
Label4.Hide()
Label5.Show()
End If
If tickCount >= 5 Then
tickCount -= 5
End If
End Sub
Private Sub Timer2_Tick(sender As Object, e As EventArgs) Handles Timer2.Tick
Label1.Invalidate()
End Sub
Private Sub Label6_Paint(sender As Object, e As PaintEventArgs) Handles Label6.Paint
Dim gr0 = e.Graphics
frameCount += 1
For n = 0 To 29
snowLargeXPos(n) = snowLargeXPos(n) + Math.Cos(frameCount / curveSlowerDowner(n))
snowLargeYPos(n) = snowLargeYPos(n) + snowLargeSpeed(n)
If snowLargeYPos(n) > 690 Then
snowLargeYPos(n) = 0
End If
gr0.DrawImage(snowLarge(n), snowLargeXPos(n), snowLargeYPos(n), 5, 5)
Next
For v = 0 To 49
snowSmallXPos(v) = snowSmallXPos(v) + Math.Cos(frameCount / curveSlowerDowner(v))
snowSmallYPos(v) = snowSmallYPos(v) + snowSmallSpeed(v)
If snowSmallYPos(v) > 690 Then
snowSmallYPos(v) = 0
End If
gr0.DrawImage(snowSmall(v), snowSmallXPos(v), snowSmallYPos(v), 3, 3)
Next
End Sub
Private Sub Label1_DoubleClick(sender As Object, e As EventArgs) Handles Label1.DoubleClick
Me.Close()
End Sub
End Class


