Line (500, 700)-(2500, 700), vbRed
Line (1500, 100)-(700, 2000), vbGreen
Line (1500, 100)-(2300, 2000), vbGreen
Line (2500, 700)-(700, 2000), vbBlue
Line (500, 700)-(2300, 2000), vbBlue
End Sub
'这是一个模拟星空的 vb 小程序,无数大小不同的彩色星星不停移动和闪烁
'在窗体添加控件:Label1,Timer1
'在属性窗口设置 Label1 的 Index 属性为 0
Private Sub Form_Load()
Me.Caption = "星空闪烁": Me.BackColor = vbBlack
Label1(0).AutoSize = True: Label1(0).Caption = "★": Label1(0).BackStyle = 0
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).ForeColor = &HFFFFFF * Rnd
Label1(I).Tag = -3 + Rnd * 7 & "|" & -3 + Rnd * 7
Label1(I).Font.Size = 5 + Rnd * 9
Next
Label1(0).Font.Size = 9
Timer1.Enabled = True: Timer1.Interval = 30
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
W = Label1(0).Height * 0.1
For I = 0 To Label1.Count - 1
S = Label1(I).ForeColor + 160
If S > &HFFFFFF Then S = 0
Label1(I).ForeColor = S
nTag = Label1(I).Tag
S = InStr(nTag, "|")
X = Left(nTag, S - 1): y = Mid(nTag, S + 1)
L = Label1(I).Left + X * W: T = Label1(I).Top + y * W
If L > Me.ScaleWidth Then L = 0
If T > Me.ScaleHeight Then T = 0
If L < -Label1(I).Width Then L = Me.ScaleWidth
If T < -Label1(I).Height Then T = Me.ScaleHeight
Label1(I).Move L, T
Next
End Sub
文章来源:
http://user.qzone.qq.com/32063270/blog/1247125497
类似的文章,雪花飘飘:
http://user.qzone.qq.com/32063270/blog/1247125091
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)