Jump to content

help with a timer

- - - - -

  • Please log in to reply
7 replies to this topic

#1
mitchel0

mitchel0

    Newbie

  • Members
  • Pip
  • 6 posts
hey guys, i need help with writing a timers current time to a string, then to display the string. i tried
dis.tostring()
and then but i cannont get the timer to show the countdown, but i cannot :( if you guys could help, id love it!

#2
gregwarner

gregwarner

    Programming God

  • Members
  • PipPipPipPipPipPipPip
  • 853 posts
  • Location:Arkansas
I don't believe you can get the time elapsed from a Timer object, as that's not what it's for, but rather for the execution of some code at regular intervals. If you need to know how much time has elapsed, you can have your timer callback function increment a variable each time it is called, and multiply that number by the timer's interval property to get the time elapsed.

Incidentally, which timer are you referring to? System.Threading.Timer or System.Timers.Timer?
Hofstadter's Law: It always takes longer than you expect, even when you take into account Hofstadter's Law.

– Douglas Hofstadter, Gödel, Escher, Bach: An Eternal Golden Braid


#3
mitchel0

mitchel0

    Newbie

  • Members
  • Pip
  • 6 posts
hmm, ok then how could i show how much time until something happens then?

#4
gregwarner

gregwarner

    Programming God

  • Members
  • PipPipPipPipPipPipPip
  • 853 posts
  • Location:Arkansas
Same thing, but in reverse. Keep a variable of the amount of time you want to wait until an event happens. In the timer's callback method, subtract a certain amount from that variable, and check it to see if it is less than or equal to zero. If it is, then your time has expired and you can have it do something else.
Hofstadter's Law: It always takes longer than you expect, even when you take into account Hofstadter's Law.

– Douglas Hofstadter, Gödel, Escher, Bach: An Eternal Golden Braid


#5
mitchel0

mitchel0

    Newbie

  • Members
  • Pip
  • 6 posts
hmmm seems easy enough, but how do i actually display on the gui the time left? and im using whatever timer you get when you drag one onto the form. thanks!

#6
Tonchi

Tonchi

    Programming Expert

  • Members
  • PipPipPipPipPipPip
  • 471 posts
  • Location:Varaždin
  • Programming Language:C, C++, C#
you can display it in textbox...just write the code to display number on textbox every time after timer gets decrement

#7
gregwarner

gregwarner

    Programming God

  • Members
  • PipPipPipPipPipPipPip
  • 853 posts
  • Location:Arkansas

// Assuming you called your decrement variable "time_left"

// and your text box TextBox1.

TextBox1.Text = time_left.ToString();


Hofstadter's Law: It always takes longer than you expect, even when you take into account Hofstadter's Law.

– Douglas Hofstadter, Gödel, Escher, Bach: An Eternal Golden Braid


#8
mitchel0

mitchel0

    Newbie

  • Members
  • Pip
  • 6 posts
thansk you a lot!




1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users