|
-
Sep 19th, 2001, 11:29 PM
#1
Thread Starter
Hyperactive Member
help with random
Can someone tell me how I can make a button move to random spots on the form??
p|-|34|2 /\/\3 f0|2 | $p34k 1337 
My TSS quote of the day: "If your haveing a bad day, just press the restart button."
-
Sep 19th, 2001, 11:40 PM
#2
Registered User
Code:
Private Sub Command1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
Dim x1 As Long, y1 As Long
x1 = Int(Rnd * (Width - Command1.Width))
y1 = Int(Rnd * (Height - Command1.Height))
Command1.Move x1, y1
End Sub
-
Sep 20th, 2001, 12:00 AM
#3
Junior Member
here's an example
I'm not sure if this is what you're looking for, but this function will randomly relocate a command button somewhere on a form:
Private Sub moveButton(cntlButton As Control)
Dim newX As Long
Dim newY As Long
Randomize
newX = Int((Me.Width - cntlButton.Width - 150) * Rnd + 15)
newY = Int((Me.Height - cntlButton.Height - 420) * Rnd + 15)
cntlButton.Move newX, newY
End Sub
Private Sub Command1_Click()
Call moveButton(Command1)
End Sub
-
Sep 20th, 2001, 12:15 AM
#4
Thread Starter
Hyperactive Member
Re: here's an example
Originally posted by mstuehler
I'm not sure if this is what you're looking for, but this function will randomly relocate a command button somewhere on a form:
Private Sub moveButton(cntlButton As Control)
Dim newX As Long
Dim newY As Long
Randomize
newX = Int((Me.Width - cntlButton.Width - 150) * Rnd + 15)
newY = Int((Me.Height - cntlButton.Height - 420) * Rnd + 15)
cntlButton.Move newX, newY
End Sub
Private Sub Command1_Click()
Call moveButton(Command1)
End Sub
can you *edited*clean*edited* that up alittle and tell me what that all do??
btw...I want it to keep going to random spots non stop
Last edited by scsa20; Sep 20th, 2001 at 12:19 AM.
p|-|34|2 /\/\3 f0|2 | $p34k 1337 
My TSS quote of the day: "If your haveing a bad day, just press the restart button."
-
Sep 20th, 2001, 12:28 AM
#5
Thread Starter
Hyperactive Member
Originally posted by Nucleus
Code:
Private Sub Command1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
Dim x1 As Long, y1 As Long
x1 = Int(Rnd * (Width - Command1.Width))
y1 = Int(Rnd * (Height - Command1.Height))
Command1.Move x1, y1
End Sub
that code work, but how can I be able to make it not be able to use Tab to get over the button??
p|-|34|2 /\/\3 f0|2 | $p34k 1337 
My TSS quote of the day: "If your haveing a bad day, just press the restart button."
-
Sep 20th, 2001, 12:53 AM
#6
Junior Member
If you use Nucleus' code (which is always a good idea), you can add the following to prevent the user from using [tab] to get to the button:
Private Sub Command1_GotFocus()
[some other object].SetFocus
End Sub
In other words, if the button you don't want the user to get is Command1, you can deflect the focus to another object (for example, Command2) using Command2.SetFocus in the GotFocus event of Command1.
Hope this helps.
Cheers!
-
Sep 20th, 2001, 01:05 AM
#7
Thread Starter
Hyperactive Member
Originally posted by mstuehler
If you use Nucleus' code (which is always a good idea), you can add the following to prevent the user from using [tab] to get to the button:
Private Sub Command1_GotFocus()
[some other object].SetFocus
End Sub
In other words, if the button you don't want the user to get is Command1, you can deflect the focus to another object (for example, Command2) using Command2.SetFocus in the GotFocus event of Command1.
Hope this helps.
Cheers!
It works!!! thank you.
p|-|34|2 /\/\3 f0|2 | $p34k 1337 
My TSS quote of the day: "If your haveing a bad day, just press the restart button."
-
Sep 20th, 2001, 04:38 AM
#8
that code work, but how can I be able to make it not be able to use Tab to get over the button??
Set the TabStop property for the button to False.
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
|