请问一下大家怎么实现那个钟的转动 请问一下大家怎么实现那个钟的转动??有这方面的所有代码没有啊????? 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 给你一段代码试试看: public partial class clock : Form { public clock() { InitializeComponent(); Timer timer = new Timer(); timer.Enabled = true; timer.Interval = 100; timer.Tick += new EventHandler(timer_Tick); } void timer_Tick(object sender, EventArgs e) { this.paintClock(this.ClientRectangle); } protected override void OnPaint(PaintEventArgs e) { base.OnPaint(e); this.drawClock(e.Graphics, e.ClipRectangle); } protected override void OnSizeChanged(EventArgs e) { base.OnSizeChanged(e); this.paintClock(this.ClientRectangle); } private void drawClock(Graphics g, Rectangle rectangle) { SolidBrush brush1 = new SolidBrush(Color.SteelBlue); SolidBrush brush2 = new SolidBrush(Color.SkyBlue); SolidBrush brush3 = new SolidBrush(Color.Teal); SolidBrush brush4 = new SolidBrush(Color.Teal); SolidBrush brush5 = new SolidBrush(Color.Black); Pen pen1 = new Pen(brush1, 2.0f); //"时点"画笔 Pen pen2 = new Pen(brush2, 1.5f); //"分点"画笔 Pen pen3 = new Pen(brush3, 0.2f); //"时针"画笔 Pen pen4 = new Pen(brush4, 0.2f); //"分针"画笔 Pen pen5 = new Pen(brush5, 1); //"秒针"画笔 Point center = new Point(this.ClientRectangle.Left + this.ClientRectangle.Width / 2, this.ClientRectangle.Top + this.ClientRectangle.Height / 2); //画表盘 for (int i = 1; i <= 60; i++) { if (i % 5 == 0) g.DrawEllipse(pen1, center.X + (int)(Math.Cos(Math.PI / 180 * i * 6) * 60), center.Y + (int)(Math.Sin(Math.PI / 180 * i * 6) * 60), 2.0f, 2.0f); else g.DrawEllipse(pen2, center.X + (int)(Math.Cos(Math.PI / 180 * i * 6) * 60), center.Y + (int)(Math.Sin(Math.PI / 180 * i * 6) * 60), 1.5f, 1.5f); } //画时针 Point ph = new Point(center.X + (int)(Math.Cos(Math.PI / 180 * ((DateTime.Now.Hour - 3) * 30 + DateTime.Now.Minute / 12 * 6)) * 40), center.Y + (int)(Math.Sin(Math.PI / 180 * ((DateTime.Now.Hour - 3) * 30 + DateTime.Now.Minute / 12 * 6)) * 40)); Point phl = new Point(center.X + (int)(Math.Cos(Math.PI / 180 * ((DateTime.Now.Hour + 3) * 30 + DateTime.Now.Minute / 12 * 6)) * 7), center.Y + (int)(Math.Sin(Math.PI / 180 * ((DateTime.Now.Hour + 3) * 30 + DateTime.Now.Minute / 12 * 6)) * 7)); Point pch1 = new Point(center.X + (int)(Math.Cos(Math.PI / 180 * ((DateTime.Now.Hour) * 30 + DateTime.Now.Minute / 12 * 6)) * -5), center.Y + (int)(Math.Sin(Math.PI / 180 * ((DateTime.Now.Hour) * 30 + DateTime.Now.Minute / 12 * 6)) * -5)); Point pch2 = new Point(center.X + (int)(Math.Cos(Math.PI / 180 * ((DateTime.Now.Hour) * 30 + DateTime.Now.Minute / 12 * 6)) * 5), center.Y + (int)(Math.Sin(Math.PI / 180 * ((DateTime.Now.Hour) * 30 + DateTime.Now.Minute / 12 * 6)) * 5)); g.FillPolygon(brush1, new Point[] { ph, pch1, phl, pch2 }); //画分针 Point pm = new Point(center.X + (int)(Math.Cos(Math.PI / 180 * (DateTime.Now.Minute - 15) * 6) * 48), center.Y + (int)(Math.Sin(Math.PI / 180 * (DateTime.Now.Minute - 15) * 6) * 48)); Point pml = new Point(center.X + (int)(Math.Cos(Math.PI / 180 * (DateTime.Now.Minute + 15) * 6) * 9), center.Y + (int)(Math.Sin(Math.PI / 180 * (DateTime.Now.Minute + 15) * 6) * 9)); Point pcm1 = new Point(center.X + (int)(Math.Cos(Math.PI / 180 * (DateTime.Now.Minute) * 6) * -4), center.Y + (int)(Math.Sin(Math.PI / 180 * (DateTime.Now.Minute) * 6) * -4)); Point pcm2 = new Point(center.X + (int)(Math.Cos(Math.PI / 180 * (DateTime.Now.Minute) * 6) * 4), center.Y + (int)(Math.Sin(Math.PI / 180 * (DateTime.Now.Minute) * 6) * 4)); g.FillPolygon(brush1, new Point[] { pm, pcm1, pml, pcm2 }); //画秒针 Point pc = new Point(center.X, center.Y); Point ps = new Point(center.X + (int)(Math.Cos(Math.PI / 180 * (DateTime.Now.Second - 15) * 6) * 48), center.Y + (int)(Math.Sin(Math.PI / 180 * (DateTime.Now.Second - 15) * 6) * 48)); g.DrawLine(pen5, pc, ps); } internal void paintClock(Rectangle rect) { if (!this.IsDisposed && this.Visible) { BufferedGraphicsContext myContext = BufferedGraphicsManager.Current; BufferedGraphics buffer = myContext.Allocate(this.CreateGraphics(), rect); if (buffer.Graphics != null) { buffer.Graphics.Clear(this.BackColor); this.drawClock(buffer.Graphics, this.ClientRectangle); } buffer.Render(); buffer.Dispose(); } } } C# 通过post发布dede(织梦)登录并发布文章 请问,这个正则表达式该怎么写? 如何实现指定网页中输入框的输入 算法大比拼,类型数组如何实现乱序排列 新手求教:在做毕业设计,希望给份C/S架构的认识管理系统源代码! .NET Mail不支持中文邮件主题及附件名? 各位大虾 如何用C#将变量复制到Windows下的剪切板里啊?? 200分请教:WinForm下大量数据显示的问题! 关于FTP上传图片问题 C#中的数据语句问题~急急急~ image类型到字符串 如何保存DataTable中特定的列?请多帮助 谢谢
{
public clock()
{
InitializeComponent();
Timer timer = new Timer();
timer.Enabled = true;
timer.Interval = 100;
timer.Tick += new EventHandler(timer_Tick);
} void timer_Tick(object sender, EventArgs e)
{
this.paintClock(this.ClientRectangle);
}
protected override void OnPaint(PaintEventArgs e)
{
base.OnPaint(e);
this.drawClock(e.Graphics, e.ClipRectangle);
}
protected override void OnSizeChanged(EventArgs e)
{
base.OnSizeChanged(e);
this.paintClock(this.ClientRectangle);
}
private void drawClock(Graphics g, Rectangle rectangle)
{
SolidBrush brush1 = new SolidBrush(Color.SteelBlue);
SolidBrush brush2 = new SolidBrush(Color.SkyBlue);
SolidBrush brush3 = new SolidBrush(Color.Teal);
SolidBrush brush4 = new SolidBrush(Color.Teal);
SolidBrush brush5 = new SolidBrush(Color.Black);
Pen pen1 = new Pen(brush1, 2.0f); //"时点"画笔
Pen pen2 = new Pen(brush2, 1.5f); //"分点"画笔
Pen pen3 = new Pen(brush3, 0.2f); //"时针"画笔
Pen pen4 = new Pen(brush4, 0.2f); //"分针"画笔
Pen pen5 = new Pen(brush5, 1); //"秒针"画笔
Point center = new Point(this.ClientRectangle.Left + this.ClientRectangle.Width / 2, this.ClientRectangle.Top + this.ClientRectangle.Height / 2);
//画表盘
for (int i = 1; i <= 60; i++)
{
if (i % 5 == 0)
g.DrawEllipse(pen1, center.X + (int)(Math.Cos(Math.PI / 180 * i * 6) * 60), center.Y + (int)(Math.Sin(Math.PI / 180 * i * 6) * 60), 2.0f, 2.0f);
else
g.DrawEllipse(pen2, center.X + (int)(Math.Cos(Math.PI / 180 * i * 6) * 60), center.Y + (int)(Math.Sin(Math.PI / 180 * i * 6) * 60), 1.5f, 1.5f);
}
//画时针
Point ph = new Point(center.X + (int)(Math.Cos(Math.PI / 180 * ((DateTime.Now.Hour - 3) * 30 + DateTime.Now.Minute / 12 * 6)) * 40), center.Y + (int)(Math.Sin(Math.PI / 180 * ((DateTime.Now.Hour - 3) * 30 + DateTime.Now.Minute / 12 * 6)) * 40));
Point phl = new Point(center.X + (int)(Math.Cos(Math.PI / 180 * ((DateTime.Now.Hour + 3) * 30 + DateTime.Now.Minute / 12 * 6)) * 7), center.Y + (int)(Math.Sin(Math.PI / 180 * ((DateTime.Now.Hour + 3) * 30 + DateTime.Now.Minute / 12 * 6)) * 7));
Point pch1 = new Point(center.X + (int)(Math.Cos(Math.PI / 180 * ((DateTime.Now.Hour) * 30 + DateTime.Now.Minute / 12 * 6)) * -5), center.Y + (int)(Math.Sin(Math.PI / 180 * ((DateTime.Now.Hour) * 30 + DateTime.Now.Minute / 12 * 6)) * -5));
Point pch2 = new Point(center.X + (int)(Math.Cos(Math.PI / 180 * ((DateTime.Now.Hour) * 30 + DateTime.Now.Minute / 12 * 6)) * 5), center.Y + (int)(Math.Sin(Math.PI / 180 * ((DateTime.Now.Hour) * 30 + DateTime.Now.Minute / 12 * 6)) * 5));
g.FillPolygon(brush1, new Point[] { ph, pch1, phl, pch2 });
//画分针
Point pm = new Point(center.X + (int)(Math.Cos(Math.PI / 180 * (DateTime.Now.Minute - 15) * 6) * 48), center.Y + (int)(Math.Sin(Math.PI / 180 * (DateTime.Now.Minute - 15) * 6) * 48));
Point pml = new Point(center.X + (int)(Math.Cos(Math.PI / 180 * (DateTime.Now.Minute + 15) * 6) * 9), center.Y + (int)(Math.Sin(Math.PI / 180 * (DateTime.Now.Minute + 15) * 6) * 9));
Point pcm1 = new Point(center.X + (int)(Math.Cos(Math.PI / 180 * (DateTime.Now.Minute) * 6) * -4), center.Y + (int)(Math.Sin(Math.PI / 180 * (DateTime.Now.Minute) * 6) * -4));
Point pcm2 = new Point(center.X + (int)(Math.Cos(Math.PI / 180 * (DateTime.Now.Minute) * 6) * 4), center.Y + (int)(Math.Sin(Math.PI / 180 * (DateTime.Now.Minute) * 6) * 4));
g.FillPolygon(brush1, new Point[] { pm, pcm1, pml, pcm2 });
//画秒针
Point pc = new Point(center.X, center.Y);
Point ps = new Point(center.X + (int)(Math.Cos(Math.PI / 180 * (DateTime.Now.Second - 15) * 6) * 48), center.Y + (int)(Math.Sin(Math.PI / 180 * (DateTime.Now.Second - 15) * 6) * 48));
g.DrawLine(pen5, pc, ps);
}
internal void paintClock(Rectangle rect)
{
if (!this.IsDisposed && this.Visible)
{
BufferedGraphicsContext myContext = BufferedGraphicsManager.Current;
BufferedGraphics buffer = myContext.Allocate(this.CreateGraphics(), rect);
if (buffer.Graphics != null)
{
buffer.Graphics.Clear(this.BackColor);
this.drawClock(buffer.Graphics, this.ClientRectangle);
}
buffer.Render();
buffer.Dispose();
}
}
}