问题描述
在鼠标移动事件中要画一条直线终点是当前点,因为鼠标的移动中这条线要不断更新,但如果执行Invalidate()使视图全部更新,会使屏幕闪烁,效果不好,使用Invalidate(Rectanglerect);矩形区域rect又不好确定,请高手指点!
解决方案
解决方案二:
不知道这个能帮你不privateboolm_MouseLine=false;privatePoint_Point=Point.Empty;privatevoidpanel2_MouseDown(objectsender,MouseEventArgse){_Point.X=e.X;_Point.Y=e.Y;m_MouseLine=true;}privatevoidpanel2_MouseMove(objectsender,MouseEventArgse){panel2.Refresh();if(m_MouseLine){Graphics_Graphics=Graphics.FromHwnd(panel2.Handle);_Graphics.DrawLine(newPen(Brushes.Black,1),_Point,newPoint(e.X,e.Y));_Graphics.Dispose();}}privatevoidpanel2_MouseUp(objectsender,MouseEventArgse){//处理图形panel2.Refresh();}
解决方案三:
新颖,我去试试.谢谢
解决方案四:
试验了,还是闪,如果要是panel控件能透明就好了,也许可以解决.
解决方案五:
双缓冲
解决方案六:
blog.csdn.net/dunao看看这个吧不闪
解决方案七:
以前回答过,再贴一遍双缓冲(和DirectDraw一个原理)namespaceWindowsFormsApplication10{publicpartialclassForm1:Form{BitmapOrgBmp=null;BitmapCacheBmp=null;publicForm1(){InitializeComponent();pictureBox1.Image=newBitmap(400,400);pictureBox1.Size=newSize(400,400);Graphicsg=Graphics.FromImage(pictureBox1.Image);g.FillEllipse(newSolidBrush(Color.Red),newRectangle(0,0,400,400));g.Dispose();OrgBmp=newBitmap(pictureBox1.Image);}privatevoidpictureBox1_MouseMove(objectsender,MouseEventArgse){CacheBmp=newBitmap(OrgBmp);Graphicsg=Graphics.FromImage(CacheBmp);g.FillRectangle(newSolidBrush(Color.Black),newRectangle(e.Location,newSize(30,30)));g.Dispose();pictureBox1.Image=CacheBmp;}}}
解决方案八:
才学C#,六楼的方法研究中......谢谢高手!