代码如下:
添加一个timer和一个label
Private Sub Form_Load()
Me.Caption = "雪花飘飘"
Me.BackColor = RGB(100, 100, 255)
Label1(0).AutoSize = True: Label1(0).BackStyle = 0
Label1(0).Caption = "*": Label1(0).ForeColor = &HFFFFFF
Randomize
For I = 0 To 40
If I > 0 Then Load Label1(I): Label1(I).Visible = True
Label1(I).Move Me.ScaleWidth * Rnd, Me.ScaleHeight * Rnd
Label1(I).Tag = Rnd * 7 - 3 & "|" & Rnd * 5 + 1
Label1(I).Font.Size = 5 + Rnd * 9
Next
Label1(0).Font.Size = 9
Timer1.Enabled = True: Timer1.Interval = 50
End Sub
Private Sub Timer1_Timer()
Dim I As Long, S As Long, T As Single, L As Single
Dim nTag As String, X As Single, y As Single, W As Single
Randomize
W = Label1(0).Height * 0.05
For I = 0 To Label1.Count - 1
nTag = Label1(I).Tag
S = InStr(nTag, "|")
X = Left(nTag, S - 1): y = Mid(nTag, S + 1)
S = Int(Rnd * 10)
If S = 0 Then X = Rnd * 11 - 5: Label1(I).Tag = X & "|" & y
L = Label1(I).Left + X * W: T = Label1(I).Top + y * W
If L < -Label1(I).Width Then L = Me.ScaleWidth
If T < -Label1(I).Height Then T = Me.ScaleHeight If L > Me.ScaleWidth Then L = -Label1(I).Width
If T > Me.ScaleHeight Then
T = -Label1(I).Height
Label1(I).Tag = Rnd * 11 - 5 & "|" & Rnd * 5 + 1
End If
Label1(I).Move L, T
Next
End Sub
本文共 15 个字数,平均阅读时长 ≈ 1分钟
评论 (0)