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);
            }
  • 相关阅读:
    JDK Base64编解码1.7和1.8的坑
    nacos部署注意点
    详解CurrentHashMap之预习篇
    SpringBoot爬坑系列
    开发之缓存与数据库优化
    jreble备注
    Unable to open debugger port (127.0.0.1:55119): java.net.SocketException "Socket closed"
    ConcurrentHashMap源码分析
    为什么要先高16位异或低16位再取模运算
    HashMap(三)之源码分析
  • 原文地址:https://www.cnblogs.com/zhanying/p/3473151.html
Copyright © 2011-2022 走看看