画表盘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);
        }
原文地址:https://www.cnblogs.com/zhanying/p/3473151.html