Click here to Skip to main content
13,001,159 members (62,373 online)
Rate this:
Please Sign up or sign in to vote.
See more:
how to use timer for time display in textbox i need c# code .
i am use visual studio 2010
Posted 11-Nov-12 2:01am
Updated 11-Nov-12 2:25am
Rate this: bad
Please Sign up or sign in to vote.

Solution 2

1) Add a timer to your form, either via the designer or via code.
2) Set the Interval property to 100 - this will cause 1/10th of a second updates.
3) Handle the Tick Event.
4) In the Tick handler, set the TextBox.Text property to DateTime.Now.ToString(formatString), where teh formatString defines what info you an't to display. Have a look here: Formatting a DateTime for display - format string description[^] for the format possibilities.

Doing the actual code is trivial, so I will leave it as an exercise for the reader! :laugh:
Rate this: bad
Please Sign up or sign in to vote.

Solution 1

next time provide more details with your question.

public Form1()
        private Timer tm = new Timer();
        private void Form1_Load(object sender, EventArgs e)
            tm.Tick += new EventHandler(tm_Tick);
            tm.Interval = 1000;
            tm.Enabled = true;
        void tm_Tick(object sender, EventArgs e)
            textBox1.Text = DateTime.Now.ToLongTimeString();

select as answer, if it helps
jahurul islam 11-Nov-12 23:26pm
Thank you.
Member 11479008 18-Mar-15 1:51am
thank you

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web02 | 2.8.170624.1 | Last Updated 11 Nov 2012
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100