Passel is right - you should be setting the control Top and Left properties to 0 when the control has moved off the bottom-right edge of the window.
Also, you will get a smoother looking motion of controls moving outside the top-left edge of the window if you test against the bottom-right corner of the control instead of the top-left corner as follows:
Code:Private Sub Timer1_Timer() Dim i As Long For i = Target.LBound To Target.UBound Target(i).Top = Target(i).Top - ((-1) ^ i) * Rnd(1) * speed Target(i).Left = Target(i).Left - ((-1) ^ i) * Rnd(1) * speed If (Target(i).Top + Target(i).Height) < 0 Or (Target(i).Left + Target(i).Width) < 0 Then Target(i).Top = Me.ScaleHeight Target(i).Left = Me.ScaleWidth ElseIf Target(i).Top > Me.ScaleHeight Or Target(i).Left > Me.ScaleWidth Then Target(i).Top = 0 Target(i).Left = 0 End If Next i End Sub




Reply With Quote
