Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 996
  • Last Modified:

Modify code to make floating Pictue stay within form boundries

How can i modify this code so picture does not disappear off the form
Sub MovePic()
Dim x As Single, y As Single, velocity As Single, angle As Single, vangle As Single
CenterPic

Me.picJackpot.ZOrder 0
    velocity = 2
    angle = Rnd * 6.283
    x = picJackpot.Left: y = picJackpot.Top
   
    Do
        If Rnd < 0.1 Then vangle = (Rnd - 0.5) * 0.5 'Change direction velocity randomly 10%chance
        angle = angle + (vangle + 6.283) Mod 6.283 'change direction
        x = x + Cos(angle) * velocity 'move position
        y = y + Sin(angle) * velocity
        picJackpot.Move x, y 'move image
        DoEvents 'threading
    Loop While mStopJackPot = False 'Forms.Count Or yourchoise
End Sub
0
isnoend2001
Asked:
isnoend2001
  • 2
1 Solution
 
Martin LissRetired ProgrammerCommented:
Sub MovePic()
Dim x As Single, y As Single, velocity As Single, angle As Single, vangle As Single
CenterPic

Me.picJackpot.ZOrder 0
    velocity = 2
    angle = Rnd * 6.283
    x = picJackpot.Left: y = picJackpot.Top
    
    Do
        If Rnd < 0.1 Then vangle = (Rnd - 0.5) * 0.5 'Change direction velocity randomly 10%chance
        angle = angle + (vangle + 6.283) Mod 6.283 'change direction
        x = x + Cos(angle) * velocity 'move position
        y = y + Sin(angle) * velocity
        If x < 0 Then x = 0
        If x + picJackpot.Width > ScaleWidth Then x = ScaleWidth - picJackpot.Width
        If y < 0 Then y = 0
        If y + picJackpot.Height > ScaleHeight Then y = ScaleHeight - picJackpot.Height
        picJackpot.Move x, y 'move image
        DoEvents 'threading
    Loop While mStopJackPot = False 'Forms.Count Or yourchoise
End Sub

Open in new window

0
 
isnoend2001Author Commented:
your the man
Thank you
0
 
Martin LissRetired ProgrammerCommented:
You're welcome and I'm glad I was able to help.

My profile contains links to some articles I've written that may interest you.
Marty - MVP 2009 to 2012
0

Featured Post

What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now