画线问题 在panel中画线。背景是绘制的若干曲线。现在需要在panel中绘制一条随鼠标运动的直线。背景曲线不改变,只需要直线随鼠标运动。如何才可避免重绘闪烁问题? 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 CClientDC dc;dc.MoveTo(bpoint);dc.LintTo(epoint); 用一个标记变量,表示鼠标是否正在画直线。Paint中判断,如果正在画直线则不重画背景曲线,否则重画背景曲线。 设置Formthis.SetStyle(ControlStyles.OptimizedDoubleBuffer | ControlStyles.ResizeRedraw | ControlStyles.AllPaintingInWmPaint, true); 重绘闪烁是你每次直接都绘制到控件上了,把它绘制到内存画布上,一次性绘制到控件上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(); Graphics gp = panel1.CreateGraphics(); gp.DrawLine(new Pen(Color.Red), new Point(10, 10), new Point(150, 10));跟这个类似自己试下就OK了 联想查询 关于Winform WebBrowser Zoom问题 c# silverlight5 连接数据库 出现跨域问题。 (急)类似电子地图程序的开发 C#怎样判断一个文件是否被打开?顶者有分!!!!!!!!! 弱弱地问:如何利用combobox来控制datagrid .net中,如何给一个datetime型的数据库字段赋一个空值? 提供几本C#原版书 给绑定控件代码传值,数据源值未改变 关于reportviewer中动态控制文本框的问题 C# 登陆!!!
dc.MoveTo(bpoint);
dc.LintTo(epoint);
Paint中判断,如果正在画直线则不重画背景曲线,否则重画背景曲线。
this.SetStyle(ControlStyles.OptimizedDoubleBuffer |
ControlStyles.ResizeRedraw |
ControlStyles.AllPaintingInWmPaint, true);
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();
Graphics gp = panel1.CreateGraphics();
gp.DrawLine(new Pen(Color.Red), new Point(10, 10), new Point(150, 10));跟这个类似
自己试下就OK了