New Timer With Event On Tick

New Timer With Event On Tick

Page 1 of 1

2 Replies - 11110 Views - Last Post: 06 May 2008 - 01:16 PM Rate Topic: -----

#1 citricube  Icon User is offline

  • D.I.C Head

Reputation: 2
  • View blog
  • Posts: 73
  • Joined: 21-January 08

New Timer With Event On Tick

Post icon  Posted 05 May 2008 - 05:18 PM

I made an array of timers and i am looking to give them all the same event when they tick.


Public Class Form1
	Dim x
	Dim r(9999) As PictureBox
	Dim track(9999) As Integer
	Dim Timer(9999) As Timer
	Dim wow = False
	Public Event Tick As EventHandler
	Dim handler As EventHandler

	Private Function makeR()
		If x = 9999 Or wow = True Then
		Else
			x -= 1
			r(x) = New PictureBox
			r(x).Image = My.Resources.n1
			r(x).Visible = True
			r(x).Top = 278
			r(x).Width = 25
			r(x).Height = 25
			r(x).Left = 12
			Controls.Add(r(x))
			track(x) = x
			Timer(x).Interval = 1
			AddHandler Timer(x).Tick, handler
			Timer(x).Start()
			wow = True
			'r(track).Top = r(track).Top + 1
			Return 0
		End If
		r(x) = New PictureBox
		r(x).Image = My.Resources.n1
		r(x).Visible = True
		r(x).Top = 278
		r(x).Width = 25
		r(x).Height = 25
		r(x).Left = 12
		Controls.Add(r(x))
		track(x) = x
		Timer(x).Interval = 1
		AddHandler Timer(x).Tick, handler
		Timer(x).Start()
		x += 1
		'r(track).Top = r(track).Top + 1
		Return 0
	End Function


  
End Class



Is This A Good Question/Topic? 0
  • +

Replies To: New Timer With Event On Tick

#2 citricube  Icon User is offline

  • D.I.C Head

Reputation: 2
  • View blog
  • Posts: 73
  • Joined: 21-January 08

Re: New Timer With Event On Tick

Posted 05 May 2008 - 05:42 PM

Sorry i left my intentions rather unclear basically i am looking to assign a new timer for every new picturebox to tell it to move up every second rather than using drag and drop timers so i can have more than one instance of a picturebox. In this case for a guitar hero like game.
Was This Post Helpful? 0
  • +
  • -

#3 citricube  Icon User is offline

  • D.I.C Head

Reputation: 2
  • View blog
  • Posts: 73
  • Joined: 21-January 08

Re: New Timer With Event On Tick

Posted 06 May 2008 - 01:16 PM

updated code only works for one picturebox though


Public Class Form1
	Dim x
	Dim r(9999) As PictureBox
	Dim track(9999) As Integer
	Dim Timer(9999) As Timer
	Dim wow = ""
	Public Event Tick As EventHandler

	Private Sub TimerEventProcessor(ByVal myObject As Object, _
										  ByVal myEventArgs As EventArgs)
		r(track(x)).Top = r(track(x)).Top - 1
	End Sub
	Private Function makeR()
		If x = 9999 Or wow = "wow" Then
			x = x - 1
			r(x) = New PictureBox
			r(x).Image = My.Resources.n1
			r(x).Visible = True
			r(x).Top = 278
			r(x).Width = 25
			r(x).Height = 25
			r(x).Left = 12
			Controls.Add(r(x))
			track(x) = x
			Timer(x) = New Timer
			Timer(x).Interval = 10
			AddHandler Timer(x).Tick, AddressOf TimerEventProcessor
			Timer(x).Start()
			wow = "wow"
			Return 0
		Else
			r(x) = New PictureBox
			r(x).Image = My.Resources.n1
			r(x).Visible = True
			r(x).Top = 278
			r(x).Width = 25
			r(x).Height = 25
			r(x).Left = 12
			Controls.Add(r(x))
			track(x) = x
			Timer(x) = New Timer
			Timer(x).Interval = 10
			AddHandler Timer(x).Tick, AddressOf TimerEventProcessor
			Timer(x).Start()
			x = x + 1
			Return 0
		End If

	End Function


  
	Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
		makeR()
		makeR()
	End Sub
End Class



Was This Post Helpful? 0
  • +
  • -

Page 1 of 1