ioriliao 发表于 2008-9-4 01:06

做了图形时钟程序.

[color=Red]开发环境:SharpDevelop 3.0[/color]
[code]
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));
        }
    }
}

[/code]
[img]http://images.cnblogs.com/cnblogs_com/ioriliao/test1.jpg.jpg[/img][attach]37253[/attach]

[[it] 本帖最后由 ioriliao 于 2008-9-23 16:02 编辑 [/it]]

baggio582 发表于 2008-9-4 17:26

有详细的源码下载的吗?
xiejinlong582@163.com

ioriliao 发表于 2008-9-5 04:21

我已发到你邮箱了.我是用的环境vs2008

ioriliao 发表于 2008-9-5 04:28

其实源码就这么几行了...

baggio582 发表于 2008-9-5 15:09

谢谢!!!
已经收到!

HERO剧终 发表于 2008-9-6 17:21

buyaoliubai@126.com

  非常感谢LZ,LZ辛苦了

redcar 发表于 2008-9-6 17:29

redcar911@163.com
多谢楼主,学习1下

wenlei2006ok 发表于 2008-9-22 15:20

有源码吗,谢谢!!!

duanchangren 发表于 2008-9-23 10:08

919728008@qq.com
不胜感激

ioriliao 发表于 2008-9-23 15:54

很多朋友向我索要源码...其实源码就是那几行...既然...
我还是发上来吧...

zsf5758 发表于 2008-9-24 15:28

zsf5754@yahoo.com.cn
谢谢楼主

ioriliao 发表于 2008-9-24 19:09

我已经发上这里来了。。。请楼上自行下载哦....

jason13168 发表于 2008-10-2 03:31

[em01] [tk05] 太好了又學習到了!
感謝樓主教學!

页: [1]

编程论坛