欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

C#實現(xiàn)漂亮的數(shù)字時鐘效果

 更新時間:2014年10月16日 10:28:58   投稿:shichen2014  
這篇文章主要介紹了C#實現(xiàn)漂亮的數(shù)字時鐘效果,涉及時間函數(shù)的應用及繪圖的方法,需要的朋友可以參考下

本文實例講述了用C#做了一個漂亮的數(shù)字時鐘。分享給大家供大家參考。

程序運行后界面如下:

實現(xiàn)技術:主要是通過Graphics類的DrawImage方法來繪制數(shù)字時鐘中所有的數(shù)字,這些數(shù)字是從網(wǎng)上找的一些圖片文件。時鐘使用DateTime中Now屬性來獲得不同的,時,分,秒,最后通過定時器來實現(xiàn)時鐘的運行狀態(tài)。

主要代碼如下:

復制代碼 代碼如下:
//將0~9數(shù)字圖片保存在Image數(shù)組中 
private Image[] image = new Bitmap[10]; 
public Form1() 

    InitializeComponent(); 
    for (int i = 0; i < 10;i++ ) 
    { 
 image[i] = new Bitmap(@"D:/編程/C#/數(shù)字時鐘/數(shù)字時鐘/Resources/"+i.ToString()+".jpg"); 
    } 

private void Form1_Paint(object sender, PaintEventArgs e) 

    Graphics g = e.Graphics; 
 
    int hh = DateTime.Now.Hour;                       //取得小時數(shù)字 
    int hh1 = hh / 10; 
    int hh2 = hh % 10; 
    g.DrawImage(image[hh1], 20, 20, 80, 180); 
    g.DrawImage(image[hh2], 100, 20, 80, 180); 
 
    int mm = DateTime.Now.Minute;                      //取得分鐘數(shù)字 
    int mm1 = mm / 10; 
    int mm2 = mm % 10; 
    g.DrawImage(image[mm1], 260, 20, 80, 180); 
    g.DrawImage(image[mm2], 340, 20, 80, 180); 
 
    int ss = DateTime.Now.Second;                       //取得秒數(shù)字 
    int ss1 = ss / 10; 
    int ss2 = ss % 10; 
    g.DrawImage(image[ss1], 500, 20, 80, 180); 
    g.DrawImage(image[ss2], 580, 20, 80, 180); 

 
private void timer1_Tick(object sender, EventArgs e)  //對窗體進行重繪 

    this.Invalidate(); 
}

另外,需要將Timer的Interval屬性設為1000mm,Enable設置為True!

希望本文所述對大家的C#程序設計有所幫助。

相關文章

最新評論