Click here to Skip to main content
Sign Up to vote bad
good
how to use timer for time display in textbox i need c# code .
i am use visual studio 2010
Posted 11 Nov '12 - 2:01
Edited 11 Nov '12 - 2:25
Nelek26.3K


2 solutions

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  
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  
Comments
jahurul islam - 11 Nov '12 - 23:26
Thank you.

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

  Print Answers RSS
Your Filters
Interested
Ignored
     
0 OriginalGriff 293
1 Sergey Alexandrovich Kryukov 143
2 Mohammed Hameed 123
3 Santhosh G_ 108
4 Lohith Korupolu 85
0 Sergey Alexandrovich Kryukov 8,266
1 OriginalGriff 6,306
2 CPallini 3,528
3 Rohan Leuva 2,703
4 Maciej Los 2,234


Advertise | Privacy | Mobile
Web04 | 2.6.130516.1 | Last Updated 11 Nov 2012
Copyright © CodeProject, 1999-2013
All Rights Reserved. Terms of Use
Layout: fixed | fluid