954,517 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Creating a moving button in vb 2005 Help

Hi ,
I already created a button "enjoy button" that i want to move in a form when the "timer start button" is clicked.
how do link the timer to the
"timer start button" and make it move?

this is what i tried so far..then am blank
first

Private Sub MainForm_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'Me.xTimer.Enabled = False
xTimer.Interval = 10

DX = 1
xDXTextBox.Text = DX

DY = 1
xDYTextBox.Text = DY


Counter = 1000
xCounterTextBox.Text = Counter

X = 216
Y = 135

Me.xButtonLabel.Text = "Button(" & X & ", " & Y & ")"

thenPrivate Sub TimeStartButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles xTimeStartButton.Click

Me.xTimer.Enabled = True

bondgirl21
Light Poster
41 posts since Feb 2009
Reputation Points: 10
Solved Threads: 0
 

xTimer.Start

then

You should use xTimer.Tick event to move your button.

martonx
Junior Poster in Training
51 posts since May 2008
Reputation Points: 10
Solved Threads: 8
 

on timer tick event
- make randomize function to get new X and Y,so your button always get new location to moving every timer tick.

Jx_Man
Nearly a Senior Poster
3,329 posts since Nov 2007
Reputation Points: 1,372
Solved Threads: 444
 

how do i randomize?
can u give me an example?

bondgirl21
Light Poster
41 posts since Feb 2009
Reputation Points: 10
Solved Threads: 0
 
how do i randomize? can u give me an example?


i got it...i used

Me.xButtonLabel.Text = "Button(" & xEnjoyButton.Location.X.ToString & ", " & xEnjoyButton.Location.Y.ToString & ")


but now i want to make the timer stop when i click the timer start button and the button stop moving aswell..how do i do that?

bondgirl21
Light Poster
41 posts since Feb 2009
Reputation Points: 10
Solved Threads: 0
 

Why would you want the timer to stop when you press the button to start the timer? lol. If you put the code to move the button in the timer_tick event, as you should have already, you just need to stop the timer like this.

Private Sub TimeStartButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles xTimeStartButton.Click

xTimer.Stop()

End Sub
crazyhorse09
Junior Poster in Training
62 posts since Mar 2009
Reputation Points: 19
Solved Threads: 7
 

Why would you want the timer to stop when you press the button to start the timer? lol. If you put the code to move the button in the timer_tick event, as you should have already, you just need to stop the timer like this.

Private Sub TimeStartButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles xTimeStartButton.Click

Me.xTimer.Stop()

End Sub

I want the timer to switch on and off when i click the "timer start button"..i just want to have one button, that's why i didnt create "timer stop button"....

bondgirl21
Light Poster
41 posts since Feb 2009
Reputation Points: 10
Solved Threads: 0
 

but now i want to use the button "start time button" as a switch to turn off and on the ticker if click...first it turns it on then off, etc.

This is what i got to start it

Private Sub TimeStartButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles xTimeStartButton.Click

        If Me.xTimeStartButton.Enabled = True Then
            Me.xTimer.Start()
        End If
bondgirl21
Light Poster
41 posts since Feb 2009
Reputation Points: 10
Solved Threads: 0
 

Ok, then try this in the button click:

If xTimer.Enabled = True Then
            xTimer.Stop()
            xTimer.Enabled = False
        ElseIf Timer1.Enabled = False Then
            xTimer.Enabled = True
            xTimer.Start()
        End If


P.S. You don't need to keep using all those "Me"s

crazyhorse09
Junior Poster in Training
62 posts since Mar 2009
Reputation Points: 19
Solved Threads: 7
 

Ok, then try this in the button click:

If xTimer.Enabled = True Then
            xTimer.Stop()
            xTimer.Enabled = False
        ElseIf Timer1.Enabled = False Then
            xTimer.Enabled = True
            xTimer.Start()
        End If

P.S. You don't need to keep using all those "Me"s


THanks it worked....oh i didn't know, i thought it was important?

bondgirl21
Light Poster
41 posts since Feb 2009
Reputation Points: 10
Solved Threads: 0
 

This question has already been solved

Post: Markdown Syntax: Formatting Help
You