Home Upgrade Search Memberlist Extras Hacker Tools Award Goals Help Wiki Contact

.NET 

[C#] on form load start timer

How can i make a timer when form loaded start timer

00:00:00
hh/mm/ss

also 1 Label that shows the exact time of form load

Example:

if the current time is : 20:30

The program should work like that:

Form loaded at: 20:30

This timer starts -----> Timer started: 00:00:00
https://www.dotnetperls.com/datetime-now

example:
this.Text = DateTime.Now.ToLongTimeString();
(Mar 8, 2019 01:33 PM)Formula 1 Wrote:  How can i make a timer when form loaded start timer

00:00:00
hh/mm/ss

also 1 Label that shows the exact time of form load

Example:

if the current time is : 20:30

The program should work like that:

Form loaded at: 20:30

This timer starts ----->   Timer started: 00:00:00

Code
var form2 = new Form2();
form2.SetLoadTime.Text = DateTime.Now.ToString("hh:mm");
form2.Show();
Code
public partial class Form2 : Form
    {
        Timer counter;
        public Label SetLoadTime
        {
            get { return label1; }
            set { label1 = value; }
        }

        public Label SetTimeAfterLoad
        {
            get { return label2; }
            set { label2 = value; }
        }

        public Form2()
        {
            InitializeComponent();
        }

        private void Form2_Load(object sender, EventArgs e)
        {
            counter = new Timer();
            counter.Interval =500;
            counter.Tick += Counter_Tick;
            counter.Start();

        }

        private void Counter_Tick(object sender, EventArgs e)
        {
            SetTimeAfterLoad.Text= DateTime.Now.ToString("hh:mm:ss");
        }
    }
buy me a coffee eth:0x88621A52aa5Eb3b6503628369687111810186c58
Why use a Timer for this?
Why not just call the method which appends the text to the label when it’s needed rather than running it on an endless loop?
[email protected]

Discord: Lord_Suspect

[0x01] I do not deal elsewhere, these are my only accounts; confirm on site before conducting business!! [0x02]


Possibly Related Threads...
Thread / Author Replies Views Last Post
[C#] by scriptsandappsFeb 14, 2022 09:04 PM 6 226 Feb 14, 2022 09:04 PM
Last Post: scriptsandapps
[.NET] by VENIJul 8, 2018 08:33 AM 3 195 Jul 8, 2018 08:33 AM
Last Post: Minto
[.NET] by HackooApr 17, 2018 10:09 AM 6 228 Apr 17, 2018 10:09 AM
Last Post: breaker1911