我是用timer来改变坐标的,也就是说在每次timer1_Tick事件中改变了变量值,然后调用的draw        private void draw(Color cColor, int iX, int iY, int iWidth, int iHeight)
        {           
            Color cTemp;
            if (cColor == Color.White)
                cTemp = Color.Black;
            else
                cTemp = Color.White;            Graphics myGraphics = this.CreateGraphics();
            myGraphics.Clear(cTemp);
            
            myGraphics.SmoothingMode = SmoothingMode.HighQuality;            myGraphics.FillEllipse(new SolidBrush(cColor), iX, iY, iWidth, iHeight);
            myGraphics.CopyFromScreen(0, 0, 0, 0, new Size(this.Width, this.Height));//这是在MSDN上看到的解决闪烁的方法,但是我加上后只能缓解闪烁,但还是要闪
        }
我把窗体的DoubleBuffered属性设置为True
上面这段代码需要怎么写才能解决闪烁的问题?

解决方案 »

  1.   

    在Paint事件里调用如下的方法,或在OnPaint方法里调用:draw(e.Graphics);然后在Timer事件里使用this.Invalidate(false);就可以了
    private   void   draw(Graphics myGraphics, Color   cColor,   int   iX,   int   iY,   int   iWidth,   int   iHeight) 
                    {                       
                            Color   cTemp; 
                            if   (cColor   ==   Color.White) 
                                    cTemp   =   Color.Black; 
                            else 
                                    cTemp   =   Color.White;                         //Graphics   myGraphics   =   this.CreateGraphics(); 
                            myGraphics.Clear(cTemp); 
                            
                            myGraphics.SmoothingMode   =   SmoothingMode.HighQuality;                         myGraphics.FillEllipse(new   SolidBrush(cColor),   iX,   iY,   iWidth,   iHeight); 
                            //myGraphics.CopyFromScreen(0,   0,   0,   0,   new   Size(this.Width,   this.Height));//这是在MSDN上看到的解决闪烁的方法,但是我加上后只能缓解闪烁,但还是要闪 
                    } 
      

  2.   

    感谢hbxtlhx,你的方法我试过了,能够解决问题,谢谢了
    顺便再问一下,如何结贴?4、如何给帖子结帖,结帖如何给分?     点击帖子左上方的管理帖子,可以进行“无满意结帖”;单独给分结帖;平均给分结帖。     注:结帖人不允许给自己的回复得分; 
    我点管理帖子后,没有   单独给分结帖;平均给分结帖  这两个DD
    到底是怎么回事哦?