以label作為跑馬燈
本周為製作跑馬燈使用軟體為visual basic 2015
物件陣列_跑馬燈
製作之程式碼
Public Class Form1
Dim lamp(99) As Label
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Dim x, y As Int16
For i As Int16 = 0 To 99
lamp(i) = New Label
x = i Mod 10
y = i \ 10
With lamp(i)
.Width = 10
.Height = 10
.BorderStyle = BorderStyle.FixedSingle
.Top = 11 * y + 20
.Left = 11 * x + 75
.BackColor = Color.Black
End With
Me.Controls.Add(lamp(i))
Next
Button1.Text = "亮下一個燈"
End Sub
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Static i, j As Int16
lamp(j).BackColor = Color.Black
lamp(i).BackColor = Color.Red
i = i + 1
j = i - 1
If i = 100 Then i = 0
End Sub
頁:
[1]