943,827 Members | Top Members by Rank

Ad:
  • VB.NET Discussion Thread
  • Marked Solved
  • Views: 2655
  • VB.NET RSS
Mar 15th, 2009
0

Creating a moving button in vb 2005 Help

Expand Post »
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
Quote ...

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 & ")"
then

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

Me.xTimer.Enabled = True
Similar Threads
Reputation Points: 10
Solved Threads: 0
Light Poster
bondgirl21 is offline Offline
41 posts
since Feb 2009
Mar 15th, 2009
0

Re: Creating a moving button in vb 2005 Help

xTimer.Start

then

You should use xTimer.Tick event to move your button.
Reputation Points: 10
Solved Threads: 8
Junior Poster in Training
martonx is offline Offline
51 posts
since May 2008
Mar 15th, 2009
0

Re: Creating a moving button in vb 2005 Help

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.
Reputation Points: 1182
Solved Threads: 392
Posting Sensei
Jx_Man is offline Offline
3,140 posts
since Nov 2007
Mar 15th, 2009
0

Re: Creating a moving button in vb 2005 Help

how do i randomize?
can u give me an example?
Reputation Points: 10
Solved Threads: 0
Light Poster
bondgirl21 is offline Offline
41 posts
since Feb 2009
Mar 15th, 2009
0

Re: Creating a moving button in vb 2005 Help

Click to Expand / Collapse  Quote originally posted by bondgirl21 ...
how do i randomize?
can u give me an example?
i got it...i used

VB.NET Syntax (Toggle Plain Text)
  1. Me.xButtonLabel.Text = "Button(" & xEnjoyButton.Location.X.ToString & ", " & xEnjoyButton.Location.Y.ToString & ")
  2.  

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?
Reputation Points: 10
Solved Threads: 0
Light Poster
bondgirl21 is offline Offline
41 posts
since Feb 2009
Mar 15th, 2009
0

Re: Creating a moving button in vb 2005 Help

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.

VB.NET Syntax (Toggle Plain Text)
  1. Private Sub TimeStartButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles xTimeStartButton.Click
  2.  
  3. xTimer.Stop()
  4.  
  5. End Sub
Last edited by crazyhorse09; Mar 15th, 2009 at 7:25 pm.
Reputation Points: 19
Solved Threads: 7
Junior Poster in Training
crazyhorse09 is offline Offline
62 posts
since Mar 2009
Mar 15th, 2009
0

Re: Creating a moving button in vb 2005 Help

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.

VB.NET Syntax (Toggle Plain Text)
  1. Private Sub TimeStartButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles xTimeStartButton.Click
  2.  
  3. Me.xTimer.Stop()
  4.  
  5. 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"....
Reputation Points: 10
Solved Threads: 0
Light Poster
bondgirl21 is offline Offline
41 posts
since Feb 2009
Mar 15th, 2009
0

Re: Creating a moving button in vb 2005 Help

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
VB.NET Syntax (Toggle Plain Text)
  1. Private Sub TimeStartButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles xTimeStartButton.Click
  2.  
  3. If Me.xTimeStartButton.Enabled = True Then
  4. Me.xTimer.Start()
  5. End If
Reputation Points: 10
Solved Threads: 0
Light Poster
bondgirl21 is offline Offline
41 posts
since Feb 2009
Mar 15th, 2009
0

Re: Creating a moving button in vb 2005 Help

Ok, then try this in the button click:

VB.NET Syntax (Toggle Plain Text)
  1. If xTimer.Enabled = True Then
  2. xTimer.Stop()
  3. xTimer.Enabled = False
  4. ElseIf Timer1.Enabled = False Then
  5. xTimer.Enabled = True
  6. xTimer.Start()
  7. End If

P.S. You don't need to keep using all those "Me"s
Last edited by crazyhorse09; Mar 15th, 2009 at 7:45 pm.
Reputation Points: 19
Solved Threads: 7
Junior Poster in Training
crazyhorse09 is offline Offline
62 posts
since Mar 2009
Mar 15th, 2009
0

Re: Creating a moving button in vb 2005 Help

Ok, then try this in the button click:

VB.NET Syntax (Toggle Plain Text)
  1. If xTimer.Enabled = True Then
  2. xTimer.Stop()
  3. xTimer.Enabled = False
  4. ElseIf Timer1.Enabled = False Then
  5. xTimer.Enabled = True
  6. xTimer.Start()
  7. 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?
Reputation Points: 10
Solved Threads: 0
Light Poster
bondgirl21 is offline Offline
41 posts
since Feb 2009

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in VB.NET Forum Timeline: Hangman Project
Next Thread in VB.NET Forum Timeline: VB Help





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC