Nikole, while this could use a whole lot of improvement, as it is a bit jerky on my system in debug mode, and it needs the transparent effect added to it. I hope it gives you some ideas...
Start a new standard exe project and add this code to form1...
Now add a form (form2) and add a timer to form2 (timer1) and add the code...Code:Option Explicit Private Sub Form_Load() Me.WindowState = vbMaximized Me.Visible = True Form2.Show vbModeless, Me Form2.Visible = True Form2.SetFocus End Sub
run and click on form2Code:Option Explicit Dim Direction As Byte, ToCenter As Boolean Private Sub Form_Click() Direction = CByte(3 * Rnd) Me.Caption = Direction Timer1.Interval = 50 Timer1.Enabled = True End Sub Private Sub Form_Load() Randomize Me.AutoRedraw = True Timer1.Enabled = False Me.Left = (Screen.Width / 2) - (Me.Width / 2) Me.Top = (Screen.Height / 2) - (Me.Height / 2) End Sub Private Sub Timer1_Timer() Dim P As Integer Select Case Direction Case 0 'headed north Me.Top = Me.Top - 150 If ToCenter = True Then If Me.Top <= ((Screen.Height / 2) - (Me.Height / 2)) Then Me.Top = (Screen.Height / 2) - (Me.Height / 2) Me.Cls Timer1.Enabled = False ToCenter = False End If Else If Me.Top <= 0 - Me.Height Then Me.Print "From the top" Direction = 2 'headed south ToCenter = True End If End If Case 1 'headed east Me.Left = Me.Left + 150 If ToCenter = True Then If Me.Left >= ((Screen.Width / 2) - (Me.Width / 2)) Then Me.Left = (Screen.Width / 2) - (Me.Width / 2) Me.Cls Timer1.Enabled = False ToCenter = False End If Else If Me.Left >= Screen.Width Then Me.Print "From the right" Direction = 3 'headed west ToCenter = True End If End If Case 2 'headed south Me.Top = Me.Top + 150 If ToCenter = True Then If Me.Top >= ((Screen.Height / 2) - (Me.Height / 2)) Then Me.Top = (Screen.Height / 2) - (Me.Height / 2) Me.Cls Timer1.Enabled = False ToCenter = False End If Else If Me.Top >= Screen.Height Then Me.Print "From the bottom" Direction = 0 ToCenter = True End If End If Case 3 Me.Left = Me.Left - 150 If ToCenter = True Then If Me.Left <= ((Screen.Width / 2) - (Me.Width / 2)) Then Me.Left = (Screen.Width / 2) - (Me.Width / 2) Me.Cls Timer1.Enabled = False ToCenter = False End If Else If Me.Left <= (0 - Me.Width) Then Me.Print "From the left" Direction = 1 ToCenter = True End If End If End Select End Sub
Improvements: Do all the calculations once in form load. Play with the timer settings and the movement rate to make it smoother/faster/etc.
Good Luck




Reply With Quote