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

c# winform時(shí)鐘的實(shí)現(xiàn)代碼

 更新時(shí)間:2014年01月15日 15:46:41   作者:  
這篇文章主要介紹了c# winform時(shí)鐘的實(shí)現(xiàn)代碼,有需要的朋友可以參考一下

代碼如下:

復(fù)制代碼 代碼如下:

using System;
 using System.Collections.Generic;
 using System.ComponentModel;
 using System.Data;
 using System.Drawing;

 using System.Text;
 using System.Windows.Forms;

 namespace Simpclock
 {
     public partial class Form1 : Form
     {
         DateTime date = DateTime.Now;

         public Form1()
         {
             InitializeComponent();

         }

         private void Form1_Load(object sender, EventArgs e)
         {
             date = DateTime.Now;

         }

         private void OnPaint(object sender, PaintEventArgs e)
         {
             Font font = new Font("Times New Roman", 20);
             Graphics g = CreateGraphics();
             g.DrawString(date.ToString(), font, Brushes.Firebrick, 10,330 );
             g.DrawString(date.DayOfWeek.ToString(), font, Brushes.Red, 250, 330);
             DrawDial(g);
             DrawSecondPointer(g);
             DrawMinutePointer(g);
             DrawHourPointer(g);

         }
         //刷新時(shí)間
         private void OnTime(object sender, EventArgs e)
         {
             date = DateTime.Now;
             Invalidate();
         }
         //畫鐘表
         //表盤部分
         Point GetPosition(int s, Point center, double radius)//定位
         {
             Point p = new Point();
             double x = center.X + radius * Math.Sin(Math.PI / 30 * s);
             double y = center.Y - radius * Math.Cos(Math.PI / 30 * s);
             p.X = (int)x;
             p.Y = (int)y;
             return p;
         }

         void DrawDial(Graphics g)//外圓及刻度
         {
             int n;
             Rectangle rect = new Rectangle(40, 10, 300, 300);
             //g.FillEllipse(Brushes.White, 40, 10, 300, 300);
             g.DrawEllipse(new Pen(Color.Black, 3), rect);
             Point p1, p2;
             Point center = new Point(190, 160);
             for (n = 0; n < 60; n++)
             {
                 p1 = GetPosition(n, center, 150);
                 if (n % 5 == 0)
                 {
                     p2 = GetPosition(n, center, 130);
                     g.DrawLine(new Pen(Color.Black, 2), p1, p2);
                 }
                 else
                 {
                     p2 = GetPosition(n, center, 140);
                     g.DrawLine(Pens.Red, p1, p2);
                 }
             }
             Font font = new Font("Times New Roman", 20);
             n = 0;
             p1 = GetPosition(n, center, 130);
             g.DrawString("XII", font, Brushes.Black, p1.X - 25, p1.Y);
             n += 15;
             p1 = GetPosition(n, center, 130);
             g.DrawString("III", font, Brushes.Black, p1.X - 35, p1.Y - 15);
             n += 15;
             p1 = GetPosition(n, center, 130);
             g.DrawString("VI", font, Brushes.Black, p1.X - 20, p1.Y - 30);
             n += 15;
             p1 = GetPosition(n, center, 130);
             g.DrawString("IX", font, Brushes.Black, p1.X, p1.Y - 15);
         }
         //秒針部分
         void DrawSecondPointer(Graphics g)
         {
             Point center = new Point(190, 160);
             Point p;
             p = GetPosition(date.Second, center, 130);
             g.DrawLine(Pens.Red, center, p);
             g.FillEllipse(Brushes.Red, new Rectangle(p.X - 2, p.Y - 2, 4, 4));

         }
         //分針部分
         void DrawMinutePointer(Graphics g)
         {
             Point center = new Point(190, 160);
             Point p;
             p = GetPosition(date.Minute, center, 120);
             g.DrawLine(Pens.Blue, center, p);
             //g.FillEllipse(Brushes.Blue, new Rectangle(p.X - 4, p.Y - 4, 8, 8));
         }
         //時(shí)針部分
         Point GetHourPosition(Point center, double radius)
         {
             Point p = new Point();
             int h = date.Hour;
             int m = date.Minute;
             double t = Math.PI / 6 * h + Math.PI / 360 * m;
             double x = center.X + radius * Math.Sin(t);
             double y = center.Y - radius * Math.Cos(t);
             p.X = (int)x;
             p.Y = (int)y;
             return p;
         }
         void DrawHourPointer(Graphics g)
         {
             Point center = new Point(190, 160);
             Point p = GetHourPosition(center, 100);
             g.DrawLine(new Pen(Brushes.Black, 2), center, p);
             //去指針圓尖
             // g.FillEllipse(Brushes.Black,
             //              new Rectangle(p.X - 6, p.Y - 6, 12, 12));
             g.FillEllipse(Brushes.YellowGreen,
             new Rectangle(center.X - 6, center.Y - 6, 12, 12));

 
         }

     }
}

相關(guān)文章

  • C#使用BinaryFormatter類、ISerializable接口、XmlSerializer類進(jìn)行序列化和反序列化

    C#使用BinaryFormatter類、ISerializable接口、XmlSerializer類進(jìn)行序列化和反序列

    這篇文章介紹了C#使用BinaryFormatter類、ISerializable接口、XmlSerializer類進(jìn)行序列化和反序列化的方法,文中通過示例代碼介紹的非常詳細(xì)。對大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下
    2022-09-09
  • WPF TextBox水印效果制作方法詳解

    WPF TextBox水印效果制作方法詳解

    這篇文章主要為大家詳細(xì)介紹了WPF TextBox水印效果的制作方法,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2017-09-09
  • C#中Backgroundworker與Thread的區(qū)別

    C#中Backgroundworker與Thread的區(qū)別

    本文主要介紹了C#中Backgroundworker與Thread的區(qū)別,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2022-06-06
  • C#基礎(chǔ)語法:方法參數(shù)詳解

    C#基礎(chǔ)語法:方法參數(shù)詳解

    這篇文章主要介紹了C#基礎(chǔ)語法:方法參數(shù)詳解,本文講解了值參數(shù)、引用參數(shù)、輸出參數(shù)、參數(shù)數(shù)組等參數(shù)類型,并分別給出代碼實(shí)例,需要的朋友可以參考下
    2015-06-06
  • C#生成XML的三種途徑小結(jié)

    C#生成XML的三種途徑小結(jié)

    為了全面,這里都將XML保存到文件中,有三種生成XML的方式,需要的朋友可以參考下
    2013-05-05
  • 簡單介紹C# 中的擴(kuò)展方法

    簡單介紹C# 中的擴(kuò)展方法

    這篇文章主要介紹了C# 中的擴(kuò)展方法的相關(guān)資料,文中講解非常細(xì)致,代碼幫助大家更好的理解和學(xué)習(xí),感興趣的朋友可以了解下
    2020-08-08
  • C#實(shí)現(xiàn)發(fā)送郵件的三種方法

    C#實(shí)現(xiàn)發(fā)送郵件的三種方法

    這篇文章主要介紹了C#實(shí)現(xiàn)發(fā)送郵件的三種方法,實(shí)例講述了Localhost,SMTP與SSL-SMTP三種實(shí)現(xiàn)方法,對于C#項(xiàng)目開發(fā)有不錯(cuò)的借鑒價(jià)值,需要的朋友可以參考下
    2014-11-11
  • C#開發(fā)教程之FTP上傳下載功能詳解

    C#開發(fā)教程之FTP上傳下載功能詳解

    這篇文章主要為大家詳細(xì)介紹了C#開發(fā)教程之FTP上傳下載功能,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2017-04-04
  • WPF模擬實(shí)現(xiàn)Gitee泡泡菜單的示例代碼

    WPF模擬實(shí)現(xiàn)Gitee泡泡菜單的示例代碼

    這篇文章主要介紹了如何利用WPF模擬實(shí)現(xiàn)Gitee泡泡菜單,文中的示例代碼講解詳細(xì),對我們學(xué)習(xí)或工作有一定幫助,需要的可以參考一下
    2022-08-08
  • Unity實(shí)現(xiàn)UI漸變效果

    Unity實(shí)現(xiàn)UI漸變效果

    這篇文章主要為大家詳細(xì)介紹了Unity實(shí)現(xiàn)UI漸變效果,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2020-04-04

最新評論