Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Ticking time on a label

Ticking time on a label

Scheduled Pinned Locked Moved C#
helpquestion
5 Posts 5 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    MorganSim
    wrote on last edited by
    #1

    Am trying to make the label's text to the current time, but not using the 'static' DateTime.Now property which I tried to use lately. How can I go about it.Please help. :((

    M A V 3 Replies Last reply
    0
    • M MorganSim

      Am trying to make the label's text to the current time, but not using the 'static' DateTime.Now property which I tried to use lately. How can I go about it.Please help. :((

      M Offline
      M Offline
      Manas Bhardwaj
      wrote on last edited by
      #2

      Use BackGroundWroker Process (i.e. a different thread) to update the time on label after every 1 sec(or whatever interval you like)

      Please remember to rate helpful or unhelpful answers, it lets us and people reading the forums know if our answers are any good.

      1 Reply Last reply
      0
      • M MorganSim

        Am trying to make the label's text to the current time, but not using the 'static' DateTime.Now property which I tried to use lately. How can I go about it.Please help. :((

        A Offline
        A Offline
        Alan Balkany
        wrote on last edited by
        #3

        You could use the Timer class, which is simpler than explicitly creating another process:

        protected Timer tim = new Timer(); // Create timer.

        ...
        // Set up timer:
        tim.Tick += new EventHandler(tim_Tick); // Called at timer intervals.
        tim.Interval = timerInterval; // Set timer interval.

        ...

        private void tim_Tick(object sender, EventArgs e)
        {
        // Set label to current time...
        }

        1 Reply Last reply
        0
        • M MorganSim

          Am trying to make the label's text to the current time, but not using the 'static' DateTime.Now property which I tried to use lately. How can I go about it.Please help. :((

          V Offline
          V Offline
          vikas amin
          wrote on last edited by
          #4

          avoid using threads to update your gui , insted use events . also you can use DateTime.Now to get the time

          Vikas Amin

          My First Article on CP" Virtual Serial Port "[^]

          modified on Thursday, July 24, 2008 5:33 PM

          P 1 Reply Last reply
          0
          • V vikas amin

            avoid using threads to update your gui , insted use events . also you can use DateTime.Now to get the time

            Vikas Amin

            My First Article on CP" Virtual Serial Port "[^]

            modified on Thursday, July 24, 2008 5:33 PM

            P Offline
            P Offline
            PIEBALDconsult
            wrote on last edited by
            #5

            I have threads update my GUI all the time, but they have to be done properly. I don't see how an event would help avoid using a thread.

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups