现在的位置: 首页 > 综合 > 正文

贝赛尔时钟

2013年10月23日 ⁄ 综合 ⁄ 共 2617字 ⁄ 字号 评论关闭
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Text;
using System.Windows.Forms;
using System.Drawing.Drawing2D;

namespace testgrid
{
    
public partial class BazierClockControl : ClockControl
    
{
        
public BazierClockControl()
        
{
            InitializeComponent();
        }

        
protected override void DrawHourHand(Graphics g, Pen pen)
        
{
            
//base.DrawHourHand(g, pen);
            GraphicsState gs = g.Save();
            g.RotateTransform(360f 
* Time.Hour / 12 + 30f * Time.Minute / 60);
            g.DrawBeziers(pen, 
new Point[] new Point(0,-600),new Point(0,-300),new Point(200,-300),new Point(50,-200),
            
new Point(50,-200),new Point(50,0),new Point(50,0),new Point(50,75),
            
new Point(-50,75),new Point(-50,0),new Point(-50,0),new Point(-50,-200),
            
new Point(-50,-200),new Point(-200,-300),new Point(0,-300),new Point(0,-600)}
);
            g.Restore(gs);
        }

        
protected override void DrawMinuteHand(Graphics g, Pen pen)
        
{
            
//base.DrawMinuteHand(g, pen);
            GraphicsState gs = g.Save();
            g.RotateTransform(360f 
* Time.Minute / 60 + 6f * Time.Second / 60);
            g.DrawBeziers(pen, 
new Point[] new Point(0,-800),new Point(0,-750),new Point(0,-700),new Point(25,-600),
            
new Point(25,-600),new Point(25,0),new Point(25,0),new Point(25,50),
            
new Point(-25,50),new Point(-25,0),new Point(-25,0),new Point(-25,-600),
            
new Point(-25,-600),new Point(0,-700),new Point(0,-750),new Point(0,-800)}
);
            g.Restore(gs);
        }

    }

}

窗体代码

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace testgrid
{
    
public partial class BezierClock : Form
    
{
        BazierClockControl clkctl;
        
public BezierClock()
        
{
            InitializeComponent();
            clkctl 
= new BazierClockControl();
            clkctl.Parent 
= this;
            clkctl.Time 
= DateTime.Now;
            clkctl.Dock 
= DockStyle.Fill;
            clkctl.BackColor 
= Color.Black;
            clkctl.ForeColor 
= Color.White;
            Timer timer 
= new Timer();
            timer.Interval 
= 100;
            timer.Tick 
+= new EventHandler(timer_Tick);
            timer.Start();
        }


        
void timer_Tick(object sender, EventArgs e)
        
{
           
// throw new Exception("The method or operation is not implemented.");
            clkctl.Time = DateTime.Now;
        }

    }

}

 

抱歉!评论已关闭.