永发信息网

如何用C#画时钟

答案:1  悬赏:80  手机版
解决时间 2021-02-08 10:22
  • 提问者网友:沦陷
  • 2021-02-07 16:00
如何用C# 画时钟,使时钟与电脑同步。。。
最佳答案
  • 五星知识达人网友:封刀令
  • 2021-02-07 17:36
int secR = 60;
int ponR = 65;
int minR = 50;
int houR = 40;
Point secondPoint;
Rectangle rect = new Rectangle(0, 0, 130, 130);
Rectangle rectMean = new Rectangle(61, 61, 8, 8);
Pen thePen = new Pen(Color.Blue, 2);
Pen thePenBig = new Pen(Color.Black, 6);
Pen thePenNormal = new Pen(Color.Black, 3);
Pen thePenSmall = new Pen(Color.Red, 1); SolidBrush sb = new SolidBrush(Color.Blue);
SolidBrush sbNum = new SolidBrush(Color.Black);
private void Clock_Load(object sender, EventArgs e)
{
this.SetStyle(ControlStyles.OptimizedDoubleBuffer, true);
this.SetStyle(ControlStyles.AllPaintingInWmPaint, true);
this.SetStyle(ControlStyles.UserPaint, true); this.BackColor = Color.Transparent;
this.Size = new Size(336, 174); this.picTime.Size = new Size(140, 130);
this.picTime.Location = new Point(25, 21);
this.picTime.BackColor = Color.Transparent; thead = new Thread(new ThreadStart(Mesosphere));
thead.Start(); }
private void Mesosphere()
{
try
{
while (true)
{
MethodInvoker mi = new MethodInvoker(Manage);
BeginInvoke(mi);
Thread.Sleep(1000);
}
}
catch
{
thead.Abort();
}
}

private void Timer()
{
Graphics gp = this.picTime.CreateGraphics();
//gp.SmoothingMode = SmoothingMode.AntiAlias; this.Refresh();
int second = DateTime.Now.Second;
int minute = DateTime.Now.Minute;
int hour = DateTime.Now.Hour; int intH, intM;
Pen thePenHour = new Pen(Color.Red, 3);
Pen thePenMinute = new Pen(Color.Green, 2);
Pen thePenSecond = new Pen(Color.Blue, 1);
//时针显示
if (hour >= 12)
intH = hour - 12;
else
intH = hour;
intM = minute / 12;
GetHour(intH, intM);
gp.DrawLine(thePenHour, ponR, ponR, secondPoint.X, secondPoint.Y);
//分针显示
#region 分针
if (minute == 0)
{
gp.DrawLine(thePenMinute, ponR, ponR, ponR, ponR - minR);
}
else if (minute > 0 && minute < 15)
{
secondPoint.X = ponR + Convert.ToInt32(minR * (Math.Cos((90 - 6 * minute) * Math.PI / 180)));
secondPoint.Y = ponR - Convert.ToInt32(minR * (Math.Sin((90 - 6 * minute) * Math.PI / 180)));
gp.DrawLine(thePenMinute, ponR, ponR, secondPoint.X, secondPoint.Y);
}
else if (minute == 15)
{
gp.DrawLine(thePenMinute, ponR, ponR, ponR + minR, ponR);
}
else if (minute > 15 && minute < 30)
{
secondPoint.X = ponR + Convert.ToInt32(minR * (Math.Cos((6 * minute - 90) * Math.PI / 180)));
secondPoint.Y = ponR + Convert.ToInt32(minR * (Math.Sin((6 * minute - 90) * Math.PI / 180)));
gp.DrawLine(thePenMinute, ponR, ponR, secondPoint.X, secondPoint.Y);
}
else if (minute == 30)
{ gp.DrawLine(thePenMinute, ponR, ponR, ponR, ponR + minR);
}
else if (minute > 30 && minute < 45)
{ secondPoint.X = ponR - Convert.ToInt32(minR * (Math.Sin((6 * minute - 180) * Math.PI / 180)));
secondPoint.Y = ponR + Convert.ToInt32(minR * (Math.Cos((6 * minute - 180) * Math.PI / 180)));
gp.DrawLine(thePenMinute, ponR, ponR, secondPoint.X, secondPoint.Y);
}
else if (minute == 45)
{ gp.DrawLine(thePenMinute, ponR, ponR, ponR - minR, ponR);
}
else if (minute > 45)
{ secondPoint.X = ponR - Convert.ToInt32(minR * (Math.Cos((6 * minute - 270) * Math.PI / 180)));
代码太多,加我QQ :420303101
我要举报
如以上回答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
点此我要举报以上问答信息
大家都在看
推荐资讯