zoukankan      html  css  js  c++  java
  • C#钟表控件

    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Linq;
    using System.Text;
    using System.Windows.Forms;
    using System.Drawing.Drawing2D;
    
    namespace WindowsTime
    {
        public partial class TimeCustomControl : Control
        {
            public TimeCustomControl()
            {
                InitializeComponent();
                this.SetStyle(ControlStyles.OptimizedDoubleBuffer | ControlStyles.ResizeRedraw | ControlStyles.AllPaintingInWmPaint, true);
            }
    
            public DateTime Time;
    
            protected override void OnPaint(PaintEventArgs pe)
            {
                base.OnPaint(pe);
            }
    
            private void timer1_Tick(object sender, EventArgs e)
            {
                this.Time = DateTime.Now;
                this.Refresh();
            }
    
            private void TimeCustomControl_Paint(object sender, PaintEventArgs e)
            {
                Graphics dc = e.Graphics;
                Pen pn = new Pen(ForeColor);
                SolidBrush br = new SolidBrush(ForeColor);
                InitCoordinates(dc);
                DrawDots(dc,br);
                DrawHourHand(dc,pn);
                DrawSecondHand(dc, pn);
                DrawMinuteHand(dc, pn);
            }
    
            public void InitCoordinates(Graphics dc)
            {
                if (this.Width == 0 || this.Height==0)
                {
                    return;
                }
                dc.TranslateTransform(this.Width / 2, this.Height / 2);
                dc.ScaleTransform(this.Height/250f,this.Width/250f);
            }
    
            public void DrawDots(Graphics dc,Brush brush)
            {
                int iSize;
                for (int i = 0; i <=59; i++)
                {
                    if (i % 5 ==0)
                    {
                        iSize = 15;
                    }
                    else
                    {
                        iSize = 5;
                    }
                    dc.FillEllipse(brush, -iSize / 2, -100 - iSize / 2, iSize, iSize);
                    dc.RotateTransform(6);
                }
            }
    
            protected virtual void DrawHourHand(Graphics grfx, Pen pn)
            {
                GraphicsState gs = grfx.Save();
                grfx.RotateTransform(360.0F * Time.Hour/12 +30.0F * Time.Minute / 60);
                grfx.DrawLine(pn, 0, 0, 0, -50);
                grfx.Restore(gs);
            }
    
            protected virtual void DrawMinuteHand(Graphics grfx, Pen pn)
            {
                GraphicsState gs = grfx.Save();
                grfx.RotateTransform(360.0F * Time.Minute/60 + 6.0F * Time.Second/60);
                grfx.DrawLine(pn, 0, 0, 0, -70);
                grfx.Restore(gs);
            }
    
            protected virtual void DrawSecondHand(Graphics grfx, Pen pn)
            {
                GraphicsState gs = grfx.Save();
                grfx.RotateTransform(360.0F * Time.Second/60);
                grfx.DrawLine(pn, 0, 0, 0, -100);
                grfx.Restore(gs);
            }
        }
    }
  • 相关阅读:
    全网最详细的Linux命令系列-ls命令
    Kubernetes 部署策略详解-转载学习
    Kubernetes工作流程--<1>
    详解CURL状态码,最全的代码列表
    Haproxy-4层和7层代理负载实战
    Keepalived+Nginx高可用实例
    实现FTP+PAM+MySQL环境,批量配置虚拟用户
    每秒处理10万订单乐视集团支付Mysql架构-转载
    构建 CDN 分发网络架构简析
    Linux系统入门简介<1>
  • 原文地址:https://www.cnblogs.com/dachie/p/1734518.html
Copyright © 2011-2022 走看看