• C#开发漂亮的数字时钟


      今天用C#做了一个漂亮的数字时钟。界面如下。

    实现技术:主要是通过Graphics类的DrawImage方法来绘制数字时钟中所有的数字,这些数字是从网上找的一些图片文件。时钟使用DateTime中Now属性来获得不同的,时,分,秒,最后通过定时器来实现时钟的运行状态。

    Main Code:

    [c-sharp] view plaincopy
    1. //将0~9数字图片保存在Image数组中  
    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:/编程/C#/数字时钟/数字时钟/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.   
    5.     int hh = DateTime.Now.Hour;                       //取得小时数字  
    6.     int hh1 = hh / 10;  
    7.     int hh2 = hh % 10;  
    8.     g.DrawImage(image[hh1], 20, 20, 80, 180);  
    9.     g.DrawImage(image[hh2], 100, 20, 80, 180);  
    10.   
    11.     int mm = DateTime.Now.Minute;                      //取得分钟数字  
    12.     int mm1 = mm / 10;  
    13.     int mm2 = mm % 10;  
    14.     g.DrawImage(image[mm1], 260, 20, 80, 180);  
    15.     g.DrawImage(image[mm2], 340, 20, 80, 180);  
    16.   
    17.     int ss = DateTime.Now.Second;                       //取得秒数字  
    18.     int ss1 = ss / 10;  
    19.     int ss2 = ss % 10;  
    20.     g.DrawImage(image[ss1], 500, 20, 80, 180);  
    21.     g.DrawImage(image[ss2], 580, 20, 80, 180);  
    22. }  
    23.   
    24. private void timer1_Tick(object sender, EventArgs e)  //对窗体进行重绘  
    25. {  
    26.     this.Invalidate();  
    27. }  

    另外,需要将Timer的Interval属性设为1000mm,Enable设置为True!

  • 相关阅读:
    2015-3-27
    2015-3-26
    2015-3-25
    2015-3-24
    oracle数据字典表 系统表
    PowerDesigner教程系列(六)概念数据模型
    PowerDesigner教程系列(五)概念数据模型
    PowerDesigner教程系列(四)概念数据模型
    PowerDesigner教程系列(三)概念数据模型
    PowerDesigner教程系列(二)概念数据模型
  • 原文地址:https://www.cnblogs.com/rr163/p/4026744.html
Copyright © 2020-2023  润新知