|
-
Oct 30th, 2002, 05:15 PM
#1
Thread Starter
Hyperactive Member
Random window position.
How do i make my app startup in a random window position?
Last edited by Chrome; Oct 30th, 2002 at 05:39 PM.
Sam.
-
Oct 30th, 2002, 05:38 PM
#2
Hyperactive Member
VB Code:
Private Sub Form_Load()
RandomFormPos Me
End Sub
Public Sub RandomFormPos(frm As Form)
Dim scrW As Integer, scrH As Integer, _
newTop As Integer, newLeft As Integer
Let scrH = Screen.Height
Let scrW = Screen.Width
Do
Randomize
newTop = Rnd * scrH
Loop Until Not newTop + frm.Height > scrH
Do
Randomize
newLeft = Rnd * scrW
Loop Until Not newLeft + frm.Width > scrW
frm.Top = newTop
frm.Left = newLeft
End Sub
Is this what you wanted?
Jason
-
Oct 30th, 2002, 05:58 PM
#3
Thread Starter
Hyperactive Member
well almsot, but that only seemes to move the app, to around 3 or 4 random places, i want it all over the screen.
please help.
-
Oct 30th, 2002, 06:02 PM
#4
Fanatic Member
Uh, will this not work??? A lot less code...
VB Code:
Private Sub Form_Load()
Randomize Timer
Form1.Top = (Rnd * (Screen.Height - 1) + 1)
Form1.Left = (Rnd * (Screen.Width - 1) + 1)
End Sub
And if you want your form to move all around the place put the code in a timer...
"A RESPECTED scientist has put forward the stunning - if unsavoury - possibility that humans are descended from sewage dumped overboard by aliens."
"First we read that we are the creation of God, then scientists say we are descended from apes. Now they say we're some sort of alien poo. How much further can we sink?"
- Robert Matthews, Science Correspondent
-
Oct 30th, 2002, 07:47 PM
#5
Frenzied Member
Originally posted by Alien_poo
Uh, will this not work??? A lot less code...
VB Code:
Private Sub Form_Load()
Randomize Timer
Form1.Top = (Rnd * (Screen.Height - 1) + 1)
Form1.Left = (Rnd * (Screen.Width - 1) + 1)
End Sub
And if you want your form to move all around the place put the code in a timer...
Your code makes the form load outside the screens view most the time BTW...
VB Code:
Private Sub Form_Load()
Randomize Timer
Form1.Top = (Rnd * (Screen.Height - 1) + 1)
Form1.Left = (Rnd * (Screen.Width - 1) + 1)
Do While Me.Top > Screen.Height
Form1.Top = (Rnd * (Screen.Height - 1) + 1)
Loop
Do While Me.Left > Screen.Width
Form1.Left = (Rnd * (Screen.Width - 1) + 1)
Loop
End Sub
Would make it choose a new possition, until it is at least viewable all the time
-
Oct 30th, 2002, 08:25 PM
#6
Here is a streamlined version of the same concept.
VB Code:
Public Sub RandomPos(frm As Form)
Dim dblLeftRange As Double
Dim dblTopRange As Double
dblLeftRange = Screen.Width - frm.Width
dblTopRange = Screen.Height - frm.Height
Randomize
frm.Move Rnd * dblLeftRange, Rnd * dblTopRange
frm.Show
End Sub
-
Oct 31st, 2002, 05:31 PM
#7
Thread Starter
Hyperactive Member
thanks all it works now, BTW i used MartinLiss's code. But thanks anywayz.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|