本人新手,问下C#如何画出来一个类似时钟的界面
任务是做一个指针式时钟,缺少一个图形界面,各位大神帮忙 --------------------编程问答-------------------- WPF干这个比较好!下面是一个Silverlight 例子,可以转换为WPF!
http://go.microsoft.com/fwlink/?LinkId=119524 --------------------编程问答-------------------- 用.Net 做!!!呵呵、、、简单!
private void Form1_Load(object sender, EventArgs e)
{
this.timer1.Start();
}
private void timer1_Tick(object sender, EventArgs e)
{
//窗体重绘
this.Refresh();
//初始变量
int r = 190;//直径
int s = 55;//秒钟
int m = 40;//分钟
int h = 25;//时钟
//创建画板
Graphics g = this.CreateGraphics();
//创建画笔
Pen p = new Pen(Color.Red);
//设置画笔的组细
p.Width = 4;
//画圆圈
//g.DrawEllipse(p, 0, 0, r, r);
#region//秒钟
//确定第一点坐标
int x1 = 95;
int y1 = 95;
//确定a和b的边长
int a = (int)(Math.Sin(DateTime.Now.Second * 6 * (2 * Math.PI / 360)) * s);
int b = (int)(Math.Cos(DateTime.Now.Second * 6 * (2 * Math.PI / 360)) * s);
//确定第二点坐标
int x2 = r / 2 + a;
int y2 = r / 2 - b;
//画秒钟
g.DrawLine(p, x1, y1, x2, y2);
#endregion
#region//分钟
//确定第一点坐标
x1 = 95;
y1 = 95;
//确定a和b的边长
a = (int)(Math.Sin(DateTime.Now.Minute * 6 * (2 * Math.PI / 360)) * m);
b = (int)(Math.Cos(DateTime.Now.Minute * 6 * (2 * Math.PI / 360)) * m);
//确定第二点坐标
x2 = r / 2 + a;
y2 = r / 2 - b;
p.Color = Color.Blue;
//画分钟
g.DrawLine(p, x1, y1, x2, y2);
#endregion
#region//时钟
//确定第一点坐标
x1 = 95;
y1 = 95;
//确定a和b的边长
a = (int)(Math.Sin(DateTime.Now.Hour *30 * (2 * Math.PI / 360)) * h);
b = (int)(Math.Cos(DateTime.Now.Hour *30 * (2 * Math.PI / 360)) * h);
//确定第二点坐标
x2 = r / 2 + a;
y2 = r / 2 - b;
p.Color = Color.Green;
//画时钟
g.DrawLine(p, x1, y1, x2, y2);
#endregion --------------------编程问答-------------------- 如果2楼代码可用的话,把timer1_Tick中的代码放到OnPaint中,timer1_Tick中调用Invalidate重绘
补充:.NET技术 , C#