做了图形时钟程序.
开发环境:SharpDevelop 3.0
程序代码:
using System;
using System.Drawing;
using System.Windows.Forms;
namespace test2
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void pictureBox_Paint(object sender, PaintEventArgs e)
{
pictureBox1.Refresh();
pset(e);
clock(Color.Khaki, 50, 4, DateTime.Now.Hour, 30, e);
clock(Color.Green, 70, 3, DateTime.Now.Minute, 6, e);
clock(Color.Red, 100, 1, DateTime.Now.Second, 6, e);
}
private void pset(PaintEventArgs e)
{
int c = 100;
int a = 0;
int b = 0;
int clockNum = 0;
string[] num = new string[] {"12","1","2","3","4","5","6","7","8","9","10","11" };
for (int i = 0; i < 360; i+=30)
{
a = (int)(c * Math.Cos(Math.PI * i / 180));
b = (int)(Math.Sin(Math.PI * i / 180) * c);
e.Graphics.DrawString(num[clockNum], this.Font, Brushes.Black, 200 + b - 9, 200 - a - 10);
e.Graphics.DrawString(num[clockNum], this.Font, Brushes.Blue, 200 + b - 12, 200 - a - 12);
clockNum++;
}
}
private void clock(Color color, int r, int width, int dt, int value, PaintEventArgs e)
{
Pen pen = new Pen(color, width);
int c = r;
int a = 0;
int b = 0;
a = (int)(c * Math.Cos(Math.PI * dt * value / 180));
b = (int)(c * Math.Sin(Math.PI * dt * value / 180));
e.Graphics.DrawLine(pen, new Point(200, 200), new Point(200 + b, 200 - a));
}
}
}
[[it] 本帖最后由 ioriliao 于 2008-9-23 16:02 编辑 [/it]]









