[RESOLVED] Move picturebox randomly....
I'm currently moving an image in a picture box across the screen (left to right) in a screensaver.
I want to improve it by starting the picturebox with its right edge at the forms left edge then as the picture box moves off the forms right hand edge I want it to reappear on the left in a random position of the forms height.
Can somebody point me in the right direction? :afrog:
Re: Move picturebox randomly....
See if this helps:
New StdExe proj, picturebox, timer
Code:
Option Explicit
Private FW As Long, FH As Long 'form dims
Private PW As Long, PH As Long 'pic dims
Private PL As Long, PT As Long 'pic curr pos
Private Sub Form_Load()
PW = Picture1.ScaleWidth
PH = Picture1.ScaleHeight
PL = Picture1.Left
PT = Picture1.Top
Randomize
Timer1.Interval = 5 'adjust for desired effect
End Sub
Private Sub Form_Resize()
FW = ScaleWidth
FH = ScaleHeight
End Sub
Private Function GetRnd(L As Long, H As Long) As Long
GetRnd = Int((H - L + 1) * Rnd + L)
End Function
Private Sub Timer1_Timer()
Static CL As Long
PL = PL + 75 'adjust for desired effect
Picture1.Left = PL
Picture1.Top = PT
If PL > FW Then
PL = -PW
PT = GetRnd(0, FH - PH)
End If
End Sub
Re: Move picturebox randomly....
Exactly what I was looking for. Cheers....