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);
            }
  • 相关阅读:
    百度PaddlePaddle入门-14(多个CPU加速训练)
    Quantum Hierarchical State Machine (量子层级状态机)
    百度PaddlePaddle入门-13(网络优化)
    MachineLearning入门-9(数据准备)
    百度PaddlePaddle入门-12(损失函数)
    MachineLearning入门-8(数据可视化)
    百度PaddlePaddle入门-11(网络结构)
    页面生命周期
    JS控制开灯关灯
    JavaScript基础知识
  • 原文地址:https://www.cnblogs.com/zhanying/p/3473151.html
Copyright © 2011-2022 走看看