界面如何。窗体上放两个label 和一个timer.
属性窗口中这是label1的一下属性 :
autoSize 设置为true
backStyle设置为0
index设置为0
记住一定要把Label1的Index设置0. 要不然程序会出现错误。 label2的caption输入 “成绩”
timer1的Interval属性设置为200.
代码如下:
Private Sub Form_KeyPress(KeyAscii As Integer)
Static SCORE As Integer
For i = 0 To 5
If UCase(Chr(KeyAscii)) = Label1(i).Caption Then
Label1(i).Caption = ""
SCORE = SCORE + 1
Exit For
End If
Next
Label2.Caption = "成绩:" & SCORE
End Sub
Private Sub Form_Load()
Label1(0).FontSize = 18
Label1(0).Caption = "A"
Randomize
For i = 1 To 5
Load Label1(i)
Label1(i).Move Rnd * Form1.ScaleWidth, 2000 * Rnd
Label1(i).Caption = Chr(Int(Rnd * 26 + 65))
Label1(i).Visible = True
Label1(i).ForeColor = QBColor(Int(Rnd * 15))
Next
End Sub
Private Sub Timer1_Timer()
Dim i As Integer
For i = 0 To 5
Label1(i).Top = Label1(i).Top + 100
If Label1(i).Top > Me.Height Then
Label1(i).Top = 0
Label1(i).Caption = Chr(Int(Rnd * 26 + 65))
End If
Next
End Sub
这个内容涉及到控件数组和动态加载控件数组,不知道你们老师是否讲过。