Visual Studio | Digital Clock in C#

24
6



In this video we will learn to create a digital clock using C#

Points covered in this video
How to use Timer in C#
How to get current time using DateTime in C#

You can download the project code for my GitHub repository

Nguồn:https://wijstaanvooronzegrondrechten.org/

24 COMMENTS

  1. Bro, one question: why does the statement read: if (hh <10) I want the clock to start at 9am and stop at 5pm.

  2. Glad I came here to watch this. This code is actually way more complicated than it has to be. The following code will give you a working digital clock without all these unnecessary conditionals.

    namespace clock
    public partial class Form1 : Form

    {

    public Form1()

    {

    InitializeComponent();

    }

    private void tick(object sender, EventArgs e)

    {

    label_hours_minutes.Text = DateTime.Now.ToString("hh:mm");

    label_seconds.Text = DateTime.Now.ToString("ss");

    }

    private void Form1_Load(object sender, EventArgs e)

    {

    timer1.Start();

    }

    }

    }

  3. var timer = new Timer(); gives me error for Timer, try type full name "new System.Windows.Forms.Timer();" no error, but timer still doesn`t work, any ideas?

  4. An informative video. But I can't seem to figure out how to make it run in VS. There are two files on github, the form.cs and the form.designer.cs . But I can't figure out how to take those files and make a working form.
    I tried adding them in to a different working form, but when I hit start, I got 9000 errors.
    I am still just learning VS.

  5. Nice video. Im new to C# and this videos help me always somehow but I have questions if you could answer or atleast help a little bit I´d appreciate.
    1st I want it to create a "Countdown Timer"to be like a "Real time" one for example : its 10 pm and the countdown is set to 2 hours, even if I close the program and open it again at 12 pm I want it to be timed out, imagine it like a licence, I can only use my program in those 2 hours.
    SOrry Horrible english. Note: even if you know only a bit of it help me plz.

  6. easiest way >>>
    private void timer1_Tick(object sender, EventArgs e)
    {
    label1.Text = DateTime.Now.ToString("HH:mm:ss");
    }

  7. Error 1 'Timer' is an ambiguous reference between 'System.Windows.Forms.Timer' and 'System.Threading.Timer'

    what should i do for this ???

  8. Good job ! But if you notice , it takes a bit of time for the clock to appear. Is there any way to make it instantaneous ?

LEAVE A REPLY

Please enter your comment!
Please enter your name here