资源简介
简单的时针程序代码,显示当前时间,及时,分,秒针的转动等简单代码
代码片段和文件信息
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
namespace 时针
{
public partial class Form1 : Form
{
int hour;
int min;
int sec;
Pen p1 = new Pen(Color.Black 2);
Pen p2 = new Pen(Color.Black 5);
Pen p3 = new Pen(Color.Black 3);
Pen p4 = new Pen(Color.Black 2);
RectangleF rec = new RectangleF(65.0f 65.0f 165.0f 165.0f);
Graphics g;
public Form1()
{
InitializeComponent();
g = this.CreateGraphics();
}
private void DrawClock(Graphics g)
{
int r = 50;
double pi = Math.PI;
DateTime time = DateTime.Now;
double secjiaodu = 2.0*pi * time.Second / 60.0;
double minjiaodu = 2.0* pi* (time.Minute / 60.0);
double hourjiaodu =2.0* pi * (time.Hour/ 12.0);
int secLength = (int)(0.95 * r);
int minLength = (int)(0.8 * r);
int hourLength = (int)(0.6 * r);
Point secP = new Point((int)(150-secLength * Math.Sin(secjiaodu-Math.PI )) (int)(150+secLength * Math.Cos(secjiaodu-Math .PI)));
Point minP = new Point((int)(150 - minLength * Math.Sin(minjiaodu - Math.PI)) (int)(150 + minLength * Math.Cos(minjiaodu - Math.PI)));
Point hourP = new Point((int)(150 - hourLength * Math.Sin(hourjiaodu - Math.PI)) (int)(150 + hourLength * Math.Cos(hourjiaodu - Math.PI)));
Point center = new Point(150 150);
g.DrawLine(p2 center hourP);
g.DrawLine(p3 center minP);
g.DrawLine(p4 center secP);
}
private void timer1_Tick(object sender EventArgs e)
{
hour = DateTime.Now.Hour;
min = DateTime.Now.Minute;
sec = DateTime.Now.Second;
label1.Text = (hour < 10) ? “0“ + hour.ToString() : hour.ToString() + “:“ + ((min < 10) ? “0“ + min.ToString() : min.ToString()) + “:“ + ((sec < 10) ? “0“ + sec.ToString() : sec.ToString());
g.Clear(this.BackColor);
DrawClock(g);
g.DrawEllipse(p1 rec);
}
}
}
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 422912 2009-01-04 22:35 时针\Setup1\Debug\setup.exe
文件 338944 2009-01-04 22:35 时针\Setup1\Debug\Setup1.msi
文件 29973 2009-01-04 22:35 时针\Setup1\Setup1.vdproj
文件 20480 2009-01-07 17:53 时针\时针\bin\Debug\时针.exe
文件 30208 2009-01-07 17:53 时针\时针\bin\Debug\时针.pdb
文件 5632 2005-11-11 22:25 时针\时针\bin\Debug\时针.vshost.exe
文件 2345 2009-01-07 17:53 时针\时针\Form1.cs
文件 2354 2009-01-07 17:53 时针\时针\Form1.Designer.cs
文件 6008 2009-01-07 17:53 时针\时针\Form1.resx
文件 842 2009-01-07 17:53 时针\时针\obj\Debug\时针.csproj.GenerateResource.Cache
文件 20480 2009-01-07 17:53 时针\时针\obj\Debug\时针.exe
文件 180 2009-01-07 17:53 时针\时针\obj\Debug\时针.Form1.resources
文件 30208 2009-01-07 17:53 时针\时针\obj\Debug\时针.pdb
文件 180 2009-01-01 12:45 时针\时针\obj\Debug\时针.Properties.Resources.resources
文件 261 2009-01-04 19:48 时针\时针\obj\时针.csproj.FileList.txt
文件 1282 2009-01-08 22:32 时针\时针\obj\时针.csproj.FileListAbsolute.txt
文件 465 2009-01-01 12:39 时针\时针\Program.cs
文件 1160 2009-01-01 12:39 时针\时针\Properties\AssemblyInfo.cs
文件 2868 2009-01-01 12:39 时针\时针\Properties\Resources.Designer.cs
文件 5612 2009-01-01 12:39 时针\时针\Properties\Resources.resx
文件 1091 2009-01-01 12:39 时针\时针\Properties\Settings.Designer.cs
文件 249 2009-01-01 12:39 时针\时针\Properties\Settings.settings
文件 3219 2009-01-01 12:45 时针\时针\时针.csproj
文件 1199 2009-01-04 22:35 时针\时针.sln
..A..H. 13824 2009-01-08 22:32 时针\时针.suo
目录 0 2009-01-04 19:59 时针\时针\obj\Debug\Refactor
目录 0 2009-01-01 12:39 时针\时针\obj\Debug\TempPE
目录 0 2009-01-09 13:57 时针\时针\bin\Debug
目录 0 2009-01-09 13:57 时针\时针\obj\Debug
目录 0 2009-01-09 13:57 时针\Setup1\Debug
............此处省略10个文件信息
- 上一篇:ST16C554扩展串口驱动程序
- 下一篇:纽扣电池座封装PCBLIB 及其参数
评论
共有 条评论