|Make a form bounce across the screen|
|By: Lorenzo Dalla Vecchia Date: 23/06/2000|
A strange tip someone had once asked me: you can set a vertical and horizzontal speed and watch your form moving across the screen and "bouncing" on the borders.
Create a Timer on the form. Set its Interval property to
something as low as 10.
Now, cut and paste the following code into the Timer event procedure:
|Static vX As Integer
Static vY As Integer
If vX = 0 Then vX = 150 'horizzontal speed
If vY = 0 Then vY = 200 'vertical speed
Me.Top = Me.Top + vY
Me.Left = Me.Left + vX
If Me.Top + Me.Height >= Screen.Height Or _
Me.Top <= 0 Then vY = -vY
If Me.Left + Me.Width >= Screen.Width Or _
Me.Left <= 0 Then vX = -vX
vX and vY are values for starting horizzontal and vertical speeds: positive values correnspond to right and down, negative values to left and up. If you set vX to 0, the form will move only vertically. If you set vY to 0, it will move only horizzontally.
|Visual Basic Programming Zone is a website by
Lorenzo Dalla Vecchia.
To contact the Webmaster, click here.
Hosted by InWind: www.inwind.it