1个回答
展开全部
Option Explicit
Dim flag(37 To 40) As Boolean
Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
Dim i
For i = 37 To 40
flag(i) = IIf(KeyCode = i, True, False)
Next
End Sub
Private Sub Form_Load()
Timer1.Interval = 100
Label1.AutoSize = True
End Sub
Private Sub Timer1_Timer()
Dim i, n
n = 200
Static x As Integer, y As Integer
For i = 37 To 40
If flag(i) = True Then Exit For
Next
Select Case i
Case 37
If Label1.Left - n + Label1.Width <= 0 Then Label1.Left = Me.ScaleWidth
Label1.Left = Label1.Left - n
Case 38
If Label1.Top - n + Label1.Height <= 0 Then Label1.Top = Me.ScaleHeight
Label1.Top = Label1.Top - n
Case 39
If Label1.Left >= Me.ScaleWidth Then Label1.Left = -1 * Label1.Width
Label1.Left = Label1.Left + n
Case 40
If Label1.Top >= Me.ScaleHeight Then Label1.Top = -1 * Label1.Height
Label1.Top = Label1.Top + n
End Select
End Sub
Dim flag(37 To 40) As Boolean
Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
Dim i
For i = 37 To 40
flag(i) = IIf(KeyCode = i, True, False)
Next
End Sub
Private Sub Form_Load()
Timer1.Interval = 100
Label1.AutoSize = True
End Sub
Private Sub Timer1_Timer()
Dim i, n
n = 200
Static x As Integer, y As Integer
For i = 37 To 40
If flag(i) = True Then Exit For
Next
Select Case i
Case 37
If Label1.Left - n + Label1.Width <= 0 Then Label1.Left = Me.ScaleWidth
Label1.Left = Label1.Left - n
Case 38
If Label1.Top - n + Label1.Height <= 0 Then Label1.Top = Me.ScaleHeight
Label1.Top = Label1.Top - n
Case 39
If Label1.Left >= Me.ScaleWidth Then Label1.Left = -1 * Label1.Width
Label1.Left = Label1.Left + n
Case 40
If Label1.Top >= Me.ScaleHeight Then Label1.Top = -1 * Label1.Height
Label1.Top = Label1.Top + n
End Select
End Sub
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询