本帖最后由 fghai25 于 2009-12-15 16:32:42 编辑

解决方案 »

  1.   

    m_GraphicsSurface这个没有清理干净,每次都往上面画东西,自然东西越来越多。两个办法解决: 
    一是每次画之前清干净他。
    二是干脆不用这个对象,直接往e.Griphics上面画。
      

  2.   

    不要直接画到表盘图像上,这样搽不掉。
    表盘可以先准备好,每秒要求重画一次。在重画中先贴表盘,然后画指针(注意timer1_Tick和FrmTimer_Paint的改动):
        #region 显示指针    /// <summary>
        /// 时针
        /// 1.把坐标系平移到用户区域的中心
        /// 2.计算当前时针的角度angle
        /// 3.在angle度画出当前的时针位置和样式
        /// 4.还原坐标系并刷新
        /// </summary>
        private void DrawHourArm(Graphics objGraphics)
        {
            objGraphics.TranslateTransform(this.ClientSize.Width / 2, this.ClientSize.Height / 2);        double hourTime = (double)DateTime.Now.Hour + (double)(DateTime.Now.Minute / 60.0);
            double angle = (hourTime / 12.0) * 360; // 2.0 * Math.PI;        objGraphics.RotateTransform(((float)angle) - 178);
            Pen hHPen = HHPen;
            hHPen.SetLineCap(LineCap.Square, LineCap.ArrowAnchor, DashCap.Triangle); //线条的起点和终点样式        
            objGraphics.DrawLine(HHPen, HPoint1, HPoint2);        objGraphics.ResetTransform();
        }    /// <summary>
        /// 分针
        /// </summary>
        private void DrawMiniteArm(Graphics objGraphics)
        {        objGraphics.TranslateTransform(this.ClientSize.Width / 2, this.ClientSize.Height / 2);        double minuteTime = (double)DateTime.Now.Minute + (double)(DateTime.Now.Second / 60.0);
            double angle = ((double)minuteTime / 60.0) * 360; // 2.0 * Math.PI;
            objGraphics.RotateTransform(((float)angle) - 183);
            Pen mMPen = MMPen;
            mMPen.SetLineCap(LineCap.Square, LineCap.ArrowAnchor, DashCap.Triangle);//线条的起点和终点样式
            objGraphics.DrawLine(mMPen, MPoint1, MPoint2);        objGraphics.ResetTransform();
        }
        /// <summary>
        /// 分针
        /// </summary>
        private void DrawSecondArm(Graphics objGraphics)
        {
            objGraphics.TranslateTransform(this.ClientSize.Width / 2, this.ClientSize.Height / 2);        double angle = ((double)DateTime.Now.Second / 60.0) * 360;//角度
            objGraphics.RotateTransform(((float)angle) - 180);
            Pen sSPen = SSPen;
            sSPen.SetLineCap(LineCap.DiamondAnchor, LineCap.ArrowAnchor, DashCap.Triangle);//线条的起点和终点样式
            objGraphics.DrawLine(sSPen, SPoint1, SPoint2);        objGraphics.ResetTransform();
        } 
        #endregion
        private void FrmTimer_Paint(object sender, PaintEventArgs e)
        {
            e.Graphics.DrawImage(m_GraphicsSurface,
                                  0,0,
                                  this.ClientRectangle.Width,
                                  this.ClientRectangle.Height);        DrawSecondArm( e.Graphics );  // 画秒针
            DrawMiniteArm( e.Graphics );  // 画分针
            DrawHourArm( e.Graphics );  // 画时针
        }    /// <summary>
        ///   每秒跳动一次
        /// </summary>
        private void timer1_Tick(object sender, EventArgs e)
        {
            this.textBox1.Text = DateTime.Now.ToString("yyyy年MM月dd日HH时mm分ss秒");
            this.Invalidate();
        }