代码如下
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;namespace WindowsFormsApplication2
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
Clock myclock = new Clock();
private void timer1_Tick(object sender, EventArgs e)
{
Pen mypen = new Pen(Color.Black, 3);
Point pt1, pt2;
for (int Hour = 0; Hour < 12; Hour++)
{
pt1 = new Point(Convert.ToInt32(myclock.Center_P.X + 100 * Math.Sin(Hour * Math.PI / 6.0)), Convert.ToInt32(myclock.Center_P.Y - 100 * Math.Cos(Hour * Math.PI / 6.0)));
pt2 = new Point(Convert.ToInt32(myclock.Center_P.X + 110 * Math.Sin(Hour * Math.PI / 6.0)), Convert.ToInt32(myclock.Center_P.Y - 110 * Math.Cos(Hour * Math.PI / 6.0)));
System.Drawing.Graphics g = this.CreateGraphics();
g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;
g.DrawLine(mypen, pt1, pt2);
}
} private void button1_Click(object sender, EventArgs e)
{ }
private void timer2_Tick(object sender, EventArgs e)
{
Pen Hour_Pen = new Pen(Color.Black, 4);
Pen Minute_Pen = new Pen(Color.Black, 3);
Pen Second_Pen = new Pen(Color.Black, 1);
Graphics g = this.CreateGraphics();
g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;
g.Clear(Color.White);
g.DrawLine(Second_Pen, myclock.Center_P, myclock.Second_P);
g.DrawLine(Minute_Pen, myclock.Center_P, myclock.Minute_P);
g.DrawLine(Hour_Pen, myclock.Center_P, myclock.Hour_P);
myclock.CalculateTime();
}
public class Clock
{ public int Hour;
public int Minute;
public int Second;
public Point Center_P;
public Point Hour_P;
public Point Minute_P;
public Point Second_P;
public Clock()
{
Hour = DateTime.Now.Hour;
Minute = DateTime.Now.Minute;
Second = DateTime.Now.Second;
Center_P = new Point(150, 150);
Second_P= new Point(Convert.ToInt32(Center_P.X +100* Math.Sin(Second * Math.PI / 30.0)), Convert.ToInt32(Center_P.Y - 100*Math.Cos(Second * Math.PI / 30.0)));
Minute_P = new Point(Convert.ToInt32(Center_P.X + 75 * Math.Sin(Minute * Math.PI / 30.0 + Second * Math.PI / 1800.0)), Convert.ToInt32(Center_P.Y - 75 * Math.Cos(Minute * Math.PI / 30.0 + Second * Math.PI / 1800.0)));
Hour_P = new Point(Convert.ToInt32(Center_P.X + 50 * Math.Sin((Hour * 30.0 + Minute * 0.5 + Second / 120.0) / 360.0 * 2 * Math.PI)), Convert.ToInt32(Center_P.Y - 50 * Math.Cos((Hour * 30.0 + Minute * 0.5 + Second / 120.0) / 360.0 * 2 * Math.PI)));
}
public void CalculateTime()
{
Second++;
if (Second == 60)
{
Second = 0;
Minute++;
if (Minute == 60)
Minute = 0;
Hour++;
if (Hour == 12)
{
Hour = 0;
}
}
}
Second_P = new Point(Convert.ToInt32(Center_P.X + 100 * Math.Sin(Second * Math.PI / 30.0)), Convert.ToInt32(Center_P.Y - 100 * Math.Cos(Second * Math.PI / 30.0)));
Minute_P = new Point(Convert.ToInt32(Center_P.X + 75 * Math.Sin(Minute * Math.PI / 30.0 + Second * Math.PI / 1800.0)), Convert.ToInt32(Center_P.Y - 75 * Math.Cos(Minute * Math.PI / 30.0 + Second * Math.PI / 1800.0)));
//Hour_P = new Point(Convert.Tolnt32(Center_P.X + 50 * Math.Sin(Hour * 30.0 + Minute * 0.5 + Second / 120.0) / 360.0 * 2 * Math.PI)), Convert.Tolnt32(Center_P.Y - 50 * Math.Cos(Hour * 30.0 + Minute * 0.5 + Second /120.0) /360.0 * 2 * Math.PI)));
Hour_P = new Point(Convert.ToInt32(Center_P.X + 50 * Math.Sin((Hour * 30.0 + Minute * 0.5 + Second / 120.0) / 360.0 * 2 * Math.PI)), Convert.ToInt32(Center_P.Y - 50 * Math.Cos((Hour * 30.0 + Minute * 0.5 + Second / 120.0) / 360.0 * 2 * Math.PI)));
}
}
}
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;namespace WindowsFormsApplication2
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
Clock myclock = new Clock();
private void timer1_Tick(object sender, EventArgs e)
{
Pen mypen = new Pen(Color.Black, 3);
Point pt1, pt2;
for (int Hour = 0; Hour < 12; Hour++)
{
pt1 = new Point(Convert.ToInt32(myclock.Center_P.X + 100 * Math.Sin(Hour * Math.PI / 6.0)), Convert.ToInt32(myclock.Center_P.Y - 100 * Math.Cos(Hour * Math.PI / 6.0)));
pt2 = new Point(Convert.ToInt32(myclock.Center_P.X + 110 * Math.Sin(Hour * Math.PI / 6.0)), Convert.ToInt32(myclock.Center_P.Y - 110 * Math.Cos(Hour * Math.PI / 6.0)));
System.Drawing.Graphics g = this.CreateGraphics();
g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;
g.DrawLine(mypen, pt1, pt2);
}
} private void button1_Click(object sender, EventArgs e)
{ }
private void timer2_Tick(object sender, EventArgs e)
{
Pen Hour_Pen = new Pen(Color.Black, 4);
Pen Minute_Pen = new Pen(Color.Black, 3);
Pen Second_Pen = new Pen(Color.Black, 1);
Graphics g = this.CreateGraphics();
g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;
g.Clear(Color.White);
g.DrawLine(Second_Pen, myclock.Center_P, myclock.Second_P);
g.DrawLine(Minute_Pen, myclock.Center_P, myclock.Minute_P);
g.DrawLine(Hour_Pen, myclock.Center_P, myclock.Hour_P);
myclock.CalculateTime();
}
public class Clock
{ public int Hour;
public int Minute;
public int Second;
public Point Center_P;
public Point Hour_P;
public Point Minute_P;
public Point Second_P;
public Clock()
{
Hour = DateTime.Now.Hour;
Minute = DateTime.Now.Minute;
Second = DateTime.Now.Second;
Center_P = new Point(150, 150);
Second_P= new Point(Convert.ToInt32(Center_P.X +100* Math.Sin(Second * Math.PI / 30.0)), Convert.ToInt32(Center_P.Y - 100*Math.Cos(Second * Math.PI / 30.0)));
Minute_P = new Point(Convert.ToInt32(Center_P.X + 75 * Math.Sin(Minute * Math.PI / 30.0 + Second * Math.PI / 1800.0)), Convert.ToInt32(Center_P.Y - 75 * Math.Cos(Minute * Math.PI / 30.0 + Second * Math.PI / 1800.0)));
Hour_P = new Point(Convert.ToInt32(Center_P.X + 50 * Math.Sin((Hour * 30.0 + Minute * 0.5 + Second / 120.0) / 360.0 * 2 * Math.PI)), Convert.ToInt32(Center_P.Y - 50 * Math.Cos((Hour * 30.0 + Minute * 0.5 + Second / 120.0) / 360.0 * 2 * Math.PI)));
}
public void CalculateTime()
{
Second++;
if (Second == 60)
{
Second = 0;
Minute++;
if (Minute == 60)
Minute = 0;
Hour++;
if (Hour == 12)
{
Hour = 0;
}
}
}
Second_P = new Point(Convert.ToInt32(Center_P.X + 100 * Math.Sin(Second * Math.PI / 30.0)), Convert.ToInt32(Center_P.Y - 100 * Math.Cos(Second * Math.PI / 30.0)));
Minute_P = new Point(Convert.ToInt32(Center_P.X + 75 * Math.Sin(Minute * Math.PI / 30.0 + Second * Math.PI / 1800.0)), Convert.ToInt32(Center_P.Y - 75 * Math.Cos(Minute * Math.PI / 30.0 + Second * Math.PI / 1800.0)));
//Hour_P = new Point(Convert.Tolnt32(Center_P.X + 50 * Math.Sin(Hour * 30.0 + Minute * 0.5 + Second / 120.0) / 360.0 * 2 * Math.PI)), Convert.Tolnt32(Center_P.Y - 50 * Math.Cos(Hour * 30.0 + Minute * 0.5 + Second /120.0) /360.0 * 2 * Math.PI)));
Hour_P = new Point(Convert.ToInt32(Center_P.X + 50 * Math.Sin((Hour * 30.0 + Minute * 0.5 + Second / 120.0) / 360.0 * 2 * Math.PI)), Convert.ToInt32(Center_P.Y - 50 * Math.Cos((Hour * 30.0 + Minute * 0.5 + Second / 120.0) / 360.0 * 2 * Math.PI)));
}
}
}
解决方案 »
- C#软件打包编译后总是只有一个exe文件
- dataGridView 获取单元格的值
- c#实现文件预览(ai,plt,dxf)
- XmlNode 只能添加子节点吗?
- System.UnauthorizedAccessException: 拒绝访问
- 如何创建调色板?
- mid窗口显示前先弹出登入的普通窗口,怎么做好呢?
- 用程序控制ctrl + a 选择TextBox中的所有的内容
- ++500分请教,类似csdn短消息接收,代码实现。给个例子。难点在框架结构下webform的刷新
- [急!]在webform中怎样把treeview存入xml文件[up有分]
- 如何设计灵活的权限管理系统
- dropdownlist从数据库中读取数据,并设定某一项被选定
timer2.Interval = 1000;
timer1.Start();
timer2.Start();
这几行。我加上去就直接Error 1 The name 'timer1' does not exist in the current context
The name 'timer2' does not exist in the current context
The name 'timer3' does not exist in the current context
The name 'timer4' does not exist in the current context
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void drawClock()
{
Graphics graphic = this.CreateGraphics();
Rectangle rect = new Rectangle(30, 76, 180, 180); graphic.Clear(Color.White); Pen myPen = new Pen(Color.Black, 1);
graphic.DrawEllipse(myPen, rect.Width / 2, rect.Height / 2, 180, 180);//画表盘
} private void Form1_Paint(object sender, PaintEventArgs e)
{
drawClock();
}
}
}