在panel中画线。背景是绘制的若干曲线。
现在需要在panel中绘制一条随鼠标运动的直线。
背景曲线不改变,只需要直线随鼠标运动。
如何才可避免重绘闪烁问题?

解决方案 »

  1.   

    CClientDC dc;
    dc.MoveTo(bpoint);
    dc.LintTo(epoint);
      

  2.   

    用一个标记变量,表示鼠标是否正在画直线。
    Paint中判断,如果正在画直线则不重画背景曲线,否则重画背景曲线。
      

  3.   

    设置Form
    this.SetStyle(ControlStyles.OptimizedDoubleBuffer |   
                        ControlStyles.ResizeRedraw | 
                        ControlStyles.AllPaintingInWmPaint, true);
      

  4.   

    重绘闪烁是你每次直接都绘制到控件上了,把它绘制到内存画布上,一次性绘制到控件上BufferedGraphicsContext currentContext = BufferedGraphicsManager.Current;
                BufferedGraphics myBuffer = currentContext.Allocate(e.Graphics, e.ClipRectangle);
                Graphics bufferGraphics = myBuffer.Graphics;
                bufferGraphics.SmoothingMode = SmoothingMode.HighQuality;
                bufferGraphics.PixelOffsetMode = PixelOffsetMode.HighSpeed;
                bufferGraphics.Clear(Color.White);
                bufferGraphics.TextRenderingHint = System.Drawing.Text.TextRenderingHint.ClearTypeGridFit;   // 反锯齿  
                  bufferGraphics.DrawLine(Pens.Black,0,0,10,10) ;
                 myBuffer.Render(e.Graphics);
                bufferGraphics.Dispose();
                myBuffer.Dispose();
      

  5.   


                Graphics gp = panel1.CreateGraphics();
                gp.DrawLine(new Pen(Color.Red), new Point(10, 10), new Point(150, 10));跟这个类似
    自己试下就OK了