iT邦幫忙

DAY 8
1

程式隨手寫系列 第 8

小功能(6)

  • 分享至 

  • xImage
  •  
        const int spi = 100;
        const int mpi = 75;
        const int hpi = 50;
        private void Clock(int h, int m, int s)
        {
            Graphics graphice = pictureBox1.CreateGraphics();
            graphice.Clear(Color.White);
            Pen pen = new Pen(Color.Black, 1);
            graphice.DrawEllipse(pen, pictureBox1.ClientRectangle);
            Point cp = new Point(pictureBox1.ClientRectangle.Width / 2, pictureBox1.ClientRectangle.Height / 2);
            Point sp = new Point((int)(cp.X + (Math.Sin(6 * s * Math.PI / 180)) * spi), (int)(cp.Y - (Math.Cos(6 * s * Math.PI / 180)) * spi));
            Point mp = new Point((int)(cp.X + (Math.Sin(6 * m * Math.PI / 180)) * mpi), (int)(cp.Y - (Math.Cos(6 * m * Math.PI / 180)) * mpi));
            Point hp = new Point((int)(cp.X + (Math.Sin(6 * h * Math.PI / 180)) * hpi), (int)(cp.Y - (Math.Cos(6 * h * Math.PI / 180)) * hpi));
            graphice.DrawLine(pen, cp, sp);
            pen = new Pen(Color.Black, 2);
            graphice.DrawLine(pen, cp, mp);
            pen = new Pen(Color.Black, 4);
            graphice.DrawLine(pen, cp, hp);
        }

        private void timer1_Tick(object sender, EventArgs e)
        {
            int h = DateTime.Now.Hour;
            int m = DateTime.Now.Minute;
            int s = DateTime.Now.Second;
            Clock(h, m, s);
            statusStrip1.Text = "當前時間: " + DateTime.Now.ToLongTimeString();
            
        }

Clock繪製


上一篇
小功能(5)
下一篇
小功能(7)
系列文
程式隨手寫20
圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

尚未有邦友留言

立即登入留言