1,453
社区成员
发帖
与我相关
我的任务
分享Dim j, i, m, n As Integer
Private Sub Form_Load()
i = 1
j = 1
m = 1
n = 1
Text1.Width = Text2.Width
Text1.Height = Text2.Height
End Sub
Private Sub Timer1_Timer()
If (Text1.Left <= 0) Then '控制text1左方边界
i = i * -1
End If
If (Text1.Left + 1.1 * Text1.Width >= Form1.Width) Then '控制text1右方边界
i = i * -1
End If
If (Text1.Top <= 0) Then '控制text1上方边界
j = j * -1
End If
If (Text1.Top + 2 * Text1.Height >= Form1.Height) Then '控制text1下方边界
j = j * -1
End If
If (Text2.Left <= 0) Then '控制text2左方边界
m = m * -1
End If
If (Text2.Left + 1.1 * Text2.Width >= Form1.Width) Then '控制text2右方边界
m = m * -1
End If
If (Text2.Top <= 0) Then '控制text2上方边界
n = n * -1
End If
If (Text2.Top + 2 * Text2.Height >= Form1.Height) Then '控制text2下方边界
n = n * -1
End If
If Abs(Text1.Top - Text2.Top) <= Abs(Text1.Height) + 50 Then
If Abs(Text1.Left - Text2.Left) <= Abs(Text1.Width) Then
j = j * -1
n = n * -1
GoTo Move
End If
End If
If Abs(Text1.Left - Text2.Left) <= Abs(Text1.Width) + 50 Then
If Abs(Text1.Top - Text2.Top) <= Abs(Text1.Height) Then
i = i * -1
m = m * -1
End If
End If
Move:
Text1.Left = Text1.Left + 40 * i
Text1.Top = Text1.Top + 40 * j
Text2.Left = Text2.Left - 40 * m
Text2.Top = Text2.Top - 40 * n
End Sub