C # Development of beautiful digital clocks

Source: Internet
Author: User

Today, I made a nice digital clock with C #. The interface is as follows.

Implementation technology: Mainly through the Graphics class DrawImage method to draw all the numbers in the digital clock, these numbers are from the Internet to find some image files. The clock uses the now property in DateTime to get different, time, minute, second, and finally the clock running state through the timer.

Main Code:

[C-sharp]View Plaincopy
  1. Save the 0~9 digital picture in the image array
  2. Private image[] Image = new bitmap[10];
  3. Public Form1 ()
  4. {
  5. InitializeComponent ();
  6. For (int i = 0; i < 10;i++)
  7. {
  8. Image[i] = new Bitmap (@"d:/Programming/c#/digital clock/digital clock/resources/" +i.tostring () +". jpg");
  9. }
  10. }

[C-sharp]View Plaincopy
  1. Private void Form1_paint (object sender, PaintEventArgs e)
  2. {
  3. Graphics g = e.graphics;
  4. int hh = DateTime.Now.Hour; //Get hour numbers
  5. int hh1 = HH/10;
  6. int hh2 = hh% 10;
  7. G.drawimage (IMAGE[HH1], 20, 20, 80, 180);
  8. G.drawimage (IMAGE[HH2], 100, 20, 80, 180);
  9. int mm = DateTime.Now.Minute; //Get minute numbers
  10. int mm1 = MM/10;
  11. int mm2 = mm% 10;
  12. G.drawimage (IMAGE[MM1], 260, 20, 80, 180);
  13. G.drawimage (image[mm2], 340, 20, 80, 180);
  14. int ss = DateTime.Now.Second; //Get seconds digits
  15. int ss1 = SS/10;
  16. int SS2 = ss% 10;
  17. G.drawimage (Image[ss1], 500, 20, 80, 180);
  18. G.drawimage (Image[ss2], 580, 20, 80, 180);
  19. }
  20. Private void Timer1_Tick (object sender, EventArgs e) //Redraw the form
  21. {
  22. This .  Invalidate ();
  23. }

Also, you need to set the timer's Interval property to 1000mm,enable to true!

C # Development of beautiful digital clocks

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.