timer event in vb 2005 /animation

making the button move according to timer

Page 1 of 1

4 Replies - 4547 Views - Last Post: 15 March 2009 - 04:01 PM Rate Topic: -----

#1 lostgirl21  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 39
  • Joined: 27-February 09

timer event in vb 2005 /animation

Posted 14 March 2009 - 10:13 PM

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



then


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

	Me.xTimer.Enabled = True



Is This A Good Question/Topic? 0
  • +

Replies To: timer event in vb 2005 /animation

#2 PsychoCoder  Icon User is offline

  • Google.Sucks.Init(true);
  • member icon

Reputation: 1642
  • View blog
  • Posts: 19,853
  • Joined: 26-July 07

Re: timer event in vb 2005 /animation

Posted 14 March 2009 - 10:18 PM

VB 2005 is VB.NET. Moved to VB.NET forum :)
Was This Post Helpful? 0
  • +
  • -

#3 Martyr2  Icon User is offline

  • Programming Theoretician
  • member icon

Reputation: 4421
  • View blog
  • Posts: 12,286
  • Joined: 18-April 07

Re: timer event in vb 2005 /animation

Posted 14 March 2009 - 10:22 PM

The timer control you started has an event called the "tick" event. Double click your timer control if you have it on the form and it should by default put you in the tick event.

This event is raised each time the timer time has elapsed. So in that event you are going to put the code which will move your button.

Your start timer button will turn the timer on, it will call its tick event after the interval has expired and in that event you will adjust the button in question's position by manipulating its left/top properties.

Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
        ' Move the button to the right 10 pixels on each tick of the timer
        button1.Left += 10
End Sub



Enjoy!

"At DIC we be tick reacting code ninjas... we hate them little bugs!" :snap:
Was This Post Helpful? 1
  • +
  • -

#4 lostgirl21  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 39
  • Joined: 27-February 09

Re: timer event in vb 2005 /animation

Posted 15 March 2009 - 02:50 PM

i used this code below.... but now i want to get the x and y to show values in the button (caption) on the form..as the button is moving

   Private Sub xTimer_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles xTimer.Tick
		' Move the button to the right 10 pixels on each tick of the timer
		xEnjoyButton.Left = xEnjoyButton.Left + xSpeed
		xEnjoyButton.Top = xEnjoyButton.Top + ySpeed

		If xEnjoyButton.Left > (Panel1.Width - xEnjoyButton.Width) Then
			xSpeed = xSpeed * -DX
			' xDXTextBox.Text = -Val(DX)
		End If
		If xEnjoyButton.Right > (Panel1.Width - xEnjoyButton.Width) Then
			xSpeed = xSpeed * DX
			'xDXTextBox.Text = DX
		End If

		If xEnjoyButton.Top > (Panel1.Height - xEnjoyButton.Height) Then
			ySpeed = ySpeed * -DY
			'xDYTextBox.Text = 1
		End If

		If xEnjoyButton.Bottom > (Panel1.Height - xEnjoyButton.Height) Then
			ySpeed = ySpeed * DY
			'xDYTextBox.Text = -1
		End If


		If xEnjoyButton.Left < 0 Then
			xSpeed = xSpeed * -DX
			' Me.xDXTextBox.Text = "DX"
		ElseIf xEnjoyButton.Right < 0 Then
			xSpeed = xSpeed * DX
			' Me.xDXTextBox.Text = "-DX"
		ElseIf xEnjoyButton.Top < 0 Then
			ySpeed = ySpeed * -DY
			' Me.xDYTextBox.Text = "DY"
		ElseIf xEnjoyButton.Bottom < 0 Then
			ySpeed = ySpeed * DY
			' Me.xDYTextBox.Text = "-DY"
		End If



Was This Post Helpful? 0
  • +
  • -

#5 lostgirl21  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 39
  • Joined: 27-February 09

Re: timer event in vb 2005 /animation

Posted 15 March 2009 - 04:01 PM

got it , i used

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


now i want the "counter text box" to speed up the display of the x and y values...how do i do that...?
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1