国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學(xué)院 > 開發(fā)設(shè)計(jì) > 正文

winform時(shí)鐘c#代碼

2019-11-17 03:24:16
字體:
供稿:網(wǎng)友

winform時(shí)鐘c#代碼

代碼如下:

  1 using System;  2  using System.Collections.Generic;  3  using System.ComponentModel;  4  using System.Data;  5  using System.Drawing;  6    7  using System.Text;  8  using System.Windows.Forms;  9   10  namespace Simpclock 11  { 12      public partial class Form1 : Form 13      { 14          DateTime date = DateTime.Now; 15   16          public Form1() 17          { 18              InitializeComponent(); 19   20          } 21   22          PRivate void Form1_Load(object sender, EventArgs e) 23          { 24              date = DateTime.Now; 25   26          } 27   28          private void OnPaint(object sender, PaintEventArgs e) 29          { 30              Font font = new Font("Times New Roman", 20); 31              Graphics g = CreateGraphics(); 32              g.DrawString(date.ToString(), font, Brushes.Firebrick, 10,330 ); 33              g.DrawString(date.DayOfWeek.ToString(), font, Brushes.Red, 250, 330); 34              DrawDial(g); 35              DrawSecondPointer(g); 36              DrawMinutePointer(g); 37              DrawHourPointer(g); 38   39          } 40          //刷新時(shí)間 41          private void OnTime(object sender, EventArgs e) 42          { 43              date = DateTime.Now; 44              Invalidate(); 45          } 46          //畫鐘表 47          //表盤部分 48          Point GetPosition(int s, Point center, double radius)//定位 49          { 50              Point p = new Point(); 51              double x = center.X + radius * Math.Sin(Math.PI / 30 * s); 52              double y = center.Y - radius * Math.Cos(Math.PI / 30 * s); 53              p.X = (int)x; 54              p.Y = (int)y; 55              return p; 56          } 57   58          void DrawDial(Graphics g)//外圓及刻度 59          { 60              int n; 61              Rectangle rect = new Rectangle(40, 10, 300, 300); 62              //g.FillEllipse(Brushes.White, 40, 10, 300, 300); 63              g.DrawEllipse(new Pen(Color.Black, 3), rect); 64              Point p1, p2; 65              Point center = new Point(190, 160); 66              for (n = 0; n < 60; n++) 67              { 68                  p1 = GetPosition(n, center, 150); 69                  if (n % 5 == 0) 70                  { 71                      p2 = GetPosition(n, center, 130); 72                      g.DrawLine(new Pen(Color.Black, 2), p1, p2); 73                  } 74                  else 75                  { 76                      p2 = GetPosition(n, center, 140); 77                      g.DrawLine(Pens.Red, p1, p2); 78                  } 79              } 80              Font font = new Font("Times New Roman", 20); 81              n = 0; 82              p1 = GetPosition(n, center, 130); 83              g.DrawString("XII", font, Brushes.Black, p1.X - 25, p1.Y); 84              n += 15; 85              p1 = GetPosition(n, center, 130); 86              g.DrawString("III", font, Brushes.Black, p1.X - 35, p1.Y - 15); 87              n += 15; 88              p1 = GetPosition(n, center, 130); 89              g.DrawString("VI", font, Brushes.Black, p1.X - 20, p1.Y - 30); 90              n += 15; 91              p1 = GetPosition(n, center, 130); 92              g.DrawString("IX", font, Brushes.Black, p1.X, p1.Y - 15); 93          } 94          //秒針部分 95          void DrawSecondPointer(Graphics g) 96          { 97              Point center = new Point(190, 160); 98              Point p; 99              p = GetPosition(date.Second, center, 130);100              g.DrawLine(Pens.Red, center, p);101              g.FillEllipse(Brushes.Red, new Rectangle(p.X - 2, p.Y - 2, 4, 4));102  103          }104          //分針部分105          void DrawMinutePointer(Graphics g)106          {107              Point center = new Point(190, 160);108              Point p;109              p = GetPosition(date.Minute, center, 120);110              g.DrawLine(Pens.Blue, center, p);111              //g.FillEllipse(Brushes.Blue, new Rectangle(p.X - 4, p.Y - 4, 8, 8));112          }113          //時(shí)針部分114          Point GetHourPosition(Point center, double radius)115          {116              Point p = new Point();117              int h = date.Hour;118              int m = date.Minute;119              double t = Math.PI / 6 * h + Math.PI / 360 * m;120              double x = center.X + radius * Math.Sin(t);121              double y = center.Y - radius * Math.Cos(t);122              p.X = (int)x;123              p.Y = (int)y;124              return p;125          }126          void DrawHourPointer(Graphics g)127          {128              Point center = new Point(190, 160);129              Point p = GetHourPosition(center, 100);130              g.DrawLine(new Pen(Brushes.Black, 2), center, p);131              //去指針圓尖 http://m.survivalescaperooms.com/sosoft/132              // g.FillEllipse(Brushes.Black,133              //              new Rectangle(p.X - 6, p.Y - 6, 12, 12));134              g.FillEllipse(Brushes.YellowGreen,135              new Rectangle(center.X - 6, center.Y - 6, 12, 12));136  137  138          }139  140      }141 }


發(fā)表評論 共有條評論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 台北县| 商洛市| 临安市| 綦江县| 堆龙德庆县| 贵阳市| 墨竹工卡县| 宜城市| 基隆市| 江门市| 宁强县| 玉树县| 武汉市| 亚东县| 曲水县| 肃北| 措勤县| 邹平县| 仁化县| 宁阳县| 彩票| 都兰县| 淮安市| 酒泉市| 信阳市| 彝良县| 同仁县| 两当县| 梅河口市| 那坡县| 望谟县| 荣昌县| 青田县| 峨山| 岐山县| 通辽市| 石棉县| 盐山县| 景德镇市| 察雅县| 图木舒克市|