Results 1 to 3 of 3

Thread: Random Location Pictureboxes

  1. #1

    Thread Starter
    Fanatic Member tim_l_012's Avatar
    Join Date
    Mar 2001
    Location
    Next to a Coffee Cup.
    Posts
    641

    Unhappy

    I want a picturebox to randomly appear anywhere on the screen (within the frame) after my timer's interval has finished. How can I do this??????????

  2. #2
    Good Ol' Platypus Sastraxi's Avatar
    Join Date
    Jan 2000
    Location
    Ontario, Canada
    Posts
    5,134
    [code]
    Private Sub Timer1_Timer()
    dim XMax
    dim YMax

    XMax=Frame1.Width - Picture1.Width
    YMax=Frame1.Height - Picture1.Height

    Randomize
    Picture1.Left=int(rnd*xmax)
    Randomize
    picture1.Top=int(rnd*ymax)

    End Sub
    All contents of the above post that aren't somebody elses are mine, not the property of some media corporation.
    (Just a heads-up)

  3. #3
    Retired VBF Adm1nistrator plenderj's Avatar
    Join Date
    Jan 2001
    Location
    Dublin, Ireland
    Posts
    10,359
    If you only want your picturebox to be positioned randomly, you'd also want to stick a

    Code:
    Timer1.Enabled = False
    into Sastraxi's code.

    - jamie
    Microsoft MVP : Visual Developer - Visual Basic [2004-2005]

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