zoukankan      html  css  js  c++  java
  • WinForm 圆形时钟

       DateTime Time;
            private void timer_Tick(object sender,EventArgs e)
            {
                this.Time = DateTime.Now;
                Invalidate();
            }
            private void UCTime_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);          //绘画时针,计算旋转的度数
                DrawMinuteHand(dc, pn);        //绘画分针
                DrawSecondHand(dc, pn);        //绘画秒针

            }
            /// <summary>
            /// 设置绘画的坐标变换
            /// </summary>
            /// <param name="dc">画布</param>
            protected 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);   //调整比例大小
            }
            /// <summary>
            /// 绘画范围界面
            /// </summary>
            /// <param name="dc">画布</param>
            /// <param name="brush">笔刷</param>
            protected 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);
                }
            }
            /// <summary>
            /// 绘画时针
            /// </summary>
            /// <param name="grfx">画布</param>
            /// <param name="pn">笔</param>
            protected virtual void DrawHourHand(Graphics grfx, Pen pn)
            {
                GraphicsState gs = grfx.Save();
                //12个小时一共360度,一刻钟30度
                grfx.RotateTransform(360.0F * Time.Hour / 12 + 30.0F * Time.Minute / 60);
                grfx.DrawLine(pn, 0, 0, 0, -50);
                grfx.Restore(gs);
            }
            /// <summary>
            /// 绘画分针
            /// </summary>
            /// <param name="grfx">画布</param>
            /// <param name="pn">笔</param>
            protected virtual void DrawMinuteHand(Graphics grfx, Pen pn)
            {
                GraphicsState gs = grfx.Save();
                //每分钟6度
                grfx.RotateTransform(360.0F * Time.Minute / 60 + 6.0F * Time.Second / 60);
                grfx.DrawLine(pn, 0, 0, 0, -70);
                grfx.Restore(gs);
            }
            /// <summary>
            /// 绘画秒针
            /// </summary>
            /// <param name="grfx">画布</param>
            /// <param name="pn">笔</param>
            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);
            }

  • 相关阅读:
    FlexPaper实现文档在线浏览
    在Asp.net网页中使用接口
    MS SQL处理双引号(DoubleQuote)函数
    AFTER (FOR) INSERT与INSTEAD OF触发器区别
    ajaxToolkit:HtmlEditorExtender控件应用
    在SQL触发器或存储过程中获取在程序登录的用户
    AjaxControlToolkit HoverMenuExtender 控件演示
    使用CultureInfo来显示中文星期
    TSQL转换日期显示格式
    Repeater控件嵌套Repeater控件
  • 原文地址:https://www.cnblogs.com/lonelyofsoul/p/winform_timer.html
Copyright © 2011-2022 走看看