Welcome to Dream.In.Code
Getting VB.NET Help is Easy!

Join 86,244 VB.NET Programmers. There are 2,245 online right now! Ask your question and get quick answers from Dream.In.Code experts. Join the #1 programming help community on the internet! Registration is fast and FREE... Join Now!

Chat LIVE With a VB.NET Expert
Powered by LivePerson.com

Register to Make This Box Go Away!

New Timer With Event On Tick

 
Reply to this topicStart new topic

New Timer With Event On Tick, New Timer With Event On Tick

citricube
post 5 May, 2008 - 05:18 PM
Post #1


New D.I.C Head

*
Joined: 21 Jan, 2008
Posts: 21




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


CODE

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
User is offlineProfile CardPM
Go to the top of the page
+Quote Post


citricube
post 5 May, 2008 - 05:42 PM
Post #2


New D.I.C Head

*
Joined: 21 Jan, 2008
Posts: 21

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.
User is offlineProfile CardPM
Go to the top of the page
+Quote Post

citricube
post 6 May, 2008 - 01:16 PM
Post #3


New D.I.C Head

*
Joined: 21 Jan, 2008
Posts: 21

updated code only works for one picturebox though

CODE


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

User is offlineProfile CardPM
Go to the top of the page
+Quote Post

Fast ReplyReply to this topicStart new topic
Time is now: 5/16/08 08:27AM

Live VB.NET Help!

VB.NET Tutorials

Reference Sheets

VB.NET Snippets

Bye Bye Ads

Free DIC T-Shirt

T-Shirt Example

Related Sites

Monthly Drawing

Thumb Drive

Partners

Top Contributors

Top 10 Kudos This Month