Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
how to use timer for time display in textbox i need c# code .
i am use visual studio 2010
Posted 11-Nov-12 3:01am
Edited 11-Nov-12 3:25am
Nelek63.5K
v2
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

Easy:
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 | :laugh:
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

next time provide more details with your question.
 
public Form1()
        {
            InitializeComponent();
        }
        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
  Permalink  
v2
Comments
jahurul islam at 11-Nov-12 23:26pm
   
Thank you.

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

  Print Answers RSS
0 OriginalGriff 7,105
1 DamithSL 5,079
2 Maciej Los 4,866
3 Sergey Alexandrovich Kryukov 4,617
4 Kornfeld Eliyahu Peter 4,384


Advertise | Privacy | Mobile
Web01 | 2.8.141223.1 | Last Updated 11 Nov 2012
Copyright © CodeProject, 1999-2014
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