我的程序中有一个功能,是让鼠标拖拽一些物体,这样在MouseMove事件中就得不停Invalidate一块区域,会出现闪烁现象,怎么才能避免这个现象?

解决方案 »

  1.   

    VS2005的话,在Form的构造函数里加这个:this.SetStyle(ControlStyles.SupportsTransparentBackColor, true);
               this.SetStyle(ControlStyles.OptimizedDoubleBuffer | ControlStyles.ResizeRedraw | ControlStyles.UserPaint, true);
      

  2.   

    加了以后还是闪...我是在Form里的一个Panel上绘图的
      

  3.   

    搞定了,原来要自己创建一个MyPanel类继承Panel,用这个来绘图.
        public class MyPanel : System.Windows.Forms.Panel
        {
            public MyPanel()
            {
                this.SetStyle(System.Windows.Forms.ControlStyles.AllPaintingInWmPaint, true);
                this.SetStyle(System.Windows.Forms.ControlStyles.DoubleBuffer, true);
                this.SetStyle(System.Windows.Forms.ControlStyles.UserPaint, true);
                this.SetStyle(System.Windows.Forms.ControlStyles.ResizeRedraw, true); 
            }
        }