Results 1 to 3 of 3

Thread: [RESOLVED] Move picturebox randomly....

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Feb 2008
    Location
    Manchester, UK
    Posts
    180

    Resolved [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?


    "And then one day you find, ten years have got behind you.
    No one told you when to run, you missed the starting gun."

  2. #2
    Fanatic Member
    Join Date
    Mar 2009
    Posts
    804

    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

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Feb 2008
    Location
    Manchester, UK
    Posts
    180

    Re: Move picturebox randomly....

    Exactly what I was looking for. Cheers....


    "And then one day you find, ten years have got behind you.
    No one told you when to run, you missed the starting gun."

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width