zoukankan      html  css  js  c++  java
  • 画表盘gdi

    private void MyDrawClock(double h, int m, int s)
            {
                Graphics g = this.CreateGraphics();
                Rectangle rect = this.ClientRectangle;
    
                g.Clear(Color.White);
    
                Pen myPen = new Pen(Color.Black,3);
                g.DrawEllipse(myPen, this.ClientRectangle.Width / 2 - 75, this.ClientRectangle.Height / 2 - 75, 150, 150);//画表盘··~画圆
    
                Point centerPoint = new Point(this.ClientRectangle.Width / 2, this.ClientRectangle.Height / 2);//表的中心点
                //计算出秒针,时针,分针的另外一个商点--难点
                Point secPoint = new Point((int)(centerPoint.X + (Math.Sin(s * Math.PI / 30) * 50)), (int)(centerPoint.Y - (Math.Cos(s * Math.PI / 30) * 50)));
                Point minPoint = new Point((int)(centerPoint.X + (Math.Sin(m * Math.PI / 30) * 40)), (int)(centerPoint.Y - (Math.Cos(m * Math.PI / 30) * 40)));
                //Point hourPoint = new Point((int)(centerPoint.X + (Math.Sin(h * Math.PI / 6) * 30) - m * Math.PI / 360), (int)(centerPoint.Y - (Math.Cos(h * Math.PI / 6) * 30) - m * Math.PI / 360));
                //Point hourPoint = new Point((int)(centerPoint.X + (Math.Sin((double)(h+m/60)*1.0 * Math.PI / 6) * 30)), (int)(centerPoint.Y - (Math.Cos((double)(h+m/60)*1.0 * Math.PI / 6) * 30)));
                Point hourPoint = new Point((int)(centerPoint.X + (Math.Sin(h * Math.PI / 6) * 30)), (int)(centerPoint.Y - (Math.Cos(h* Math.PI / 6) * 30)));
                //时针指半格,当12:30的时候时针不是指向整12点的,所以要传一个非整形的h
                //以不同颜色和宽度绘制表针
                myPen = new Pen(Color.Red, 1);
                g.DrawLine(myPen, centerPoint, secPoint);
                myPen = new Pen(Color.Green, 2);
                g.DrawLine(myPen, centerPoint, minPoint);
                myPen = new Pen(Color.Orange, 4);
                g.DrawLine(myPen, centerPoint, hourPoint);
                g.Dispose();
                myPen.Dispose();
                
            }
    
            private void timer1_Tick(object sender, EventArgs e)
            {
    
                
                int s = DateTime.Now.Second;
               
                int m = DateTime.Now.Minute;
                double h = Math.Round((float)m / 60 * 1.0+DateTime.Now.Hour,1);
                MyDrawClock(h, m, s);
            }
  • 相关阅读:
    BigDecimal工具类处理精度计算
    Redis的简单使用和介绍
    数据库优化知识总结
    js弹出QQ对话框在线交谈
    火焰灯menu修改之后,可以实现数遍点击小方块停留在当前页面
    js作用域的一个小例子
    js中this的四种调用模式
    jquery火焰等效果导航菜单
    appserver配置虚拟主机
    一个类似百度文库选中弹出个小框的效果
  • 原文地址:https://www.cnblogs.com/zhanying/p/3473151.html
Copyright © 2011-2022 走看看