日期:2014-05-18  浏览次数:21012 次

GDI+ 所画的线移动时,闪烁问题,高手来
C# code

private void Frm_Report_MouseMove(object sender, MouseEventArgs e)
        {
            if (isClick)
            {
                if (count == 1)
                {
                    if (e.Y >= 10)
                    {
                        p1.Y = e.Y;
                        p2.Y = e.Y;
                    }
                    else
                    {
                        p1.Y = 10;
                        p2.Y = 10;
                    }
                    if (e.Y <= Height / 2 - 40)
                    {
                        p1.Y = e.Y;
                        p2.Y = e.Y;
                    }
                    else
                    {
                        p1.Y = Height / 2 - 40;
                        p2.Y = Height / 2 - 40;
                    }

                    this.Refresh();
                }
                if (count == 2)
                {
                    if (e.Y <= Height - 10)
                    {
                        p3.Y = e.Y;
                        p4.Y = e.Y;
                    }
                    else
                    {
                        p3.Y = Height - 10;
                        p4.Y = Height - 10;
                    }
                    if (e.Y >= Height / 2 + 40)
                    {
                        p3.Y = e.Y;
                        p4.Y = e.Y;
                    }
                    else
                    {
                        p3.Y = Height / 2 + 40;
                        p4.Y = Height / 2 + 40;
                    }
                    this.Refresh();
                }
                if (count == 3)
                {
                    if (e.X >= 10)
                    {
                        p5.X = e.X;
                        p6.X = e.X;
                    }
                    else
                    {
                        p5.X = 10;
                        p6.X = 10;
                    }
                    if (e.X <= Width / 2 - 40)
                    {
                        p5.X = e.X;
                        p6.X = e.X;
                    }
                    else
                    {
                        p5.X = Width / 2 - 40;
                        p6.X = Width / 2 - 40;
                    }
                    this.Refresh();
                }
                if (count == 4)
                {
                    if (e.X <= Width - 10)
                    {
                        p7.X = e.X;
                        p8.X = e.X;
                    }
                    else
                    {
                        p7.X = Width - 10;
                        p8.X = Width - 10;
                    }
                    if (e.X >= Width / 2 + 40)
                    {
                        p7.X = e.X;
                        p8.X = e.X;
                    }
                    else
                    {
                        p7.X = Width / 2 + 40;
                        p8.X = Width / 2 + 40;
                    }
                    this.Refresh();
                }


            }
        }



效果图片暂时不懂的怎么插入,求高手指教,用GDI画了四条虚线,当移动一条虚线时,移动过程中界面闪烁的厉害,如何修改以上代码,改变界面闪烁状态

------解决方案--------------------
初始化时 this.DoubleBuffered = true;
MouseMove中调用this.Invalidate()重绘,绘图代码写到OnPaint中