vb.net - How can I make Timer do different things based on how it was started -


how can make timer different things depends on activated it? i've tried using code

dim integer = 0 dim b integer = 0  private sub button1_mousehover(sender object, e eventargs) handles button1.mousehover     timer1.start end sub  private sub button2_mousehover(sender object, e eventargs) handles button2.mousehover     timer1.start end sub  private sub timer1_tick(sender object, e eventargs) handles timer1.tick, button2.mousehover, button1.mousehover     if sender button1         = + 1         textbox1.text =     end if      if sender button2         b = b + 1         textbox2.text = b     end if end sub 

but textbox add 1 once. means timer act 1 time not continuously timer do. there wrong there, or can different?.

another possibly simpler approach, use timer.tag property , use 1 handler both buttons:

private sub button_click(sender object, e eventargs) handles button1.click, button2.click     timer1.tag = sender     timer1.start() end sub  private sub timer1_tick(sender object, e eventargs) handles timer1.tick     += 1     if timer1.tag button2         textbox1.text = a.tostring     end if     if timer1.tag button1         textbox2.text = a.tostring     end if end sub 

since tag of type object no external casting needed.

i included start function, since wasn't sure how you're starting timer. if you're doing in different manner can left out of button event handler


Comments

Popular posts from this blog

java - SSE Emitter : Manage timeouts and complete() -

jquery - uncaught exception: DataTables Editor - remote hosting of code not allowed -

java - How to resolve error - package com.squareup.okhttp3 doesn't exist? -