Dim sp As Integer
Dim d As Integer ’0:上 1:下 2:左 3:右
Private Sub Command1_Click()
Label1.Left = Label1.Left - sp
If Label1.Left <= 0 Then Label1.Left = Form1.Width
End Sub
Private Sub Command2_Click()
Label1.Left = Label1.Left + sp
If Label1.Left >= Form1.Width Then Label1.Left = 0
End Sub
Private Sub Command3_Click()
Label1.Top = Label1.Top - sp
If Label1.Top <= 0 Then Label1.Top = Form1.Height
End Sub
Private Sub Command4_Click()
Label1.Top = Label1.Top + sp
If Label1.Top >= Form1.Height Then Label1.Top = 0
End Sub
Private Sub Command5_Click() ’上
d = 0
End Sub
Private Sub Command6_Click() ’左
d = 2
End Sub
Private Sub Command7_Click() ’右
d = 3
End Sub
Private Sub Command8_Click() ’下
d = 1
End Sub
Private Sub Command9_Click()
If Timer1.Enabled = True Then
Timer1.Enabled = False
Else
Timer1.Enabled = True
End If
End Sub
Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
Select Case KeyCode
Case 38
Label1.Top = Label1.Top - sp ’上
If Label1.Top <= 0 Then Label1.Top = Form1.Height
Case 40
Label1.Top = Label1.Top + sp ’下
If Label1.Top >= Form1.Height Then Label1.Top = 0
Case 37
Label1.Left = Label1.Left - sp ’左
If Label1.Left <= 0 Then Label1.Left = Form1.Width
Case 39
Label1.Left = Label1.Left + sp ’右
If Label1.Left >= Form1.Width Then Label1.Left = 0
End Select
End Sub
Private Sub Form_Load()
sp = 200
Command1.Enabled = False
Command2.Enabled = False
Command3.Enabled = False
Command4.Enabled = False
Command5.Enabled = False
Command6.Enabled = False
Command7.Enabled = False
Command8.Enabled = False
Command9.Enabled = False
End Sub
Private Sub Timer1_Timer()
Select Case KeyCode
Case 38
Label1.Top = Label1.Top - sp ’上
If Label1.Top <= 0 Then Label1.Top = Form1.Height
Case 40
Label1.Top = Label1.Top + sp ’下
If Label1.Top >= Form1.Height Then Label1.Top = 0
Case 37
Label1.Left = Label1.Left - sp ’左
If Label1.Left <= 0 Then Label1.Left = Form1.Width
Case 39
Label1.Left = Label1.Left + sp ’右
If Label1.Left >= Form1.Width Then Label1.Left = 0
End Select
End Sub
文章定位: