private void timer1_Tick(object sender, EventArgs e)
{
g = tabControlPanel2.CreateGraphics();
Pen P1 = new Pen(Color.Blue, 2);
g.DrawEllipse(P1, 80, 30, 230, 230);
g.DrawEllipse(new Pen(Color.Blue), 90, 40, 210, 210);
Point point3 = new Point((230 / 2 + 80), (230 / 2 + 30));
Point point4 = new Point(((int)(230 / 2 + 80 + 230 / 2 * System.Math.Sin(1.57 + j))), ((int)(230 / 2 + 30 - 230 / 2*System.Math.Cos(1.57 + j))));
//point3.X = 230 / 2 + 80;
//point3.Y = 230 / 2 + 30;
//point4.X = (int)(230 / 2 + 80 + 230 / 2 * System.Math.Sin(1.57 + j));
//point4.Y = (int)(230 / 2 + 30 - 230 / 2 * System.Math.Cos(1.57 + j)); g.DrawLine(new Pen(Color.Blue), point3, point4);
j = j + 0.5;
} timer1.Interval = 50;
请问为什么会不停的闪烁,太老火了,我不想让它闪烁,应该怎么办啊
{
g = tabControlPanel2.CreateGraphics();
Pen P1 = new Pen(Color.Blue, 2);
g.DrawEllipse(P1, 80, 30, 230, 230);
g.DrawEllipse(new Pen(Color.Blue), 90, 40, 210, 210);
Point point3 = new Point((230 / 2 + 80), (230 / 2 + 30));
Point point4 = new Point(((int)(230 / 2 + 80 + 230 / 2 * System.Math.Sin(1.57 + j))), ((int)(230 / 2 + 30 - 230 / 2*System.Math.Cos(1.57 + j))));
//point3.X = 230 / 2 + 80;
//point3.Y = 230 / 2 + 30;
//point4.X = (int)(230 / 2 + 80 + 230 / 2 * System.Math.Sin(1.57 + j));
//point4.Y = (int)(230 / 2 + 30 - 230 / 2 * System.Math.Cos(1.57 + j)); g.DrawLine(new Pen(Color.Blue), point3, point4);
j = j + 0.5;
} timer1.Interval = 50;
请问为什么会不停的闪烁,太老火了,我不想让它闪烁,应该怎么办啊
解决方案 »
- C#中如何禁止WindowsMediaPlayer双击全屏显示?
- 高分求解释winform datagridview中的一个问题
- 求解决按钮点击复制
- 项目打包时我想在服务器安装完成后加入客户端的选择安装,应该怎么做,另外WEB安装项目不能选择路径问题
- smtp的问题
- 用C#上传文件?
- TreeView 删除问题:全部删除,以及删除父节点及其子节点
- NetworkStream如何确定文件已经传送完毕
- 验证控件 验证同一类型的控件
- <C#高级编程>p77的程序,大家实现了吗?
- member names cannot be the same as their enclosing type这个问题今天让我碰上了?
- 流程中的分发汇总问题。
直接用GDI+多次绘制到控件速度太慢。导致在CLEAR的时候速度无法到达视觉的刷新速度
建议用双缓存……
先在内存理新建一个Graphic然后在这个Graphic里面吧图片组合好 然后在把组合好的图片整体画在控件的Graphic上 这个样子可以有效减少闪烁
如果还不行就双缓冲+DrawDib
在你窗体的构造函数内添加下面代码,来开启双缓冲即可:
//开启双缓冲
base.SetStyle(ControlStyles.OptimizedDoubleBuffer |
ControlStyles.AllPaintingInWmPaint |
ControlStyles.UserPaint, true);
base.SetStyle(ControlStyles.ResizeRedraw | ControlStyles.Selectable, true);建议搂主先添加这两句代码后,再看看效果如何
private void timer1_Tick(object sender, EventArgs e)
{
g = tabControlPanel2.CreateGraphics();
Pen P1 = new Pen(Color.Blue, 2);
g.DrawEllipse(P1, 80, 30, 230, 230);
p1.Width = 1;
g.DrawEllipse(p1, 90, 40, 210, 210);
Point point3 = new Point((230 / 2 + 80), (230 / 2 + 30));
Point point4 = new Point(((int)(230 / 2 + 80 + 230 / 2 * System.Math.Sin(1.57 + j))), ((int)(230 / 2 + 30 - 230 / 2*System.Math.Cos(1.57 + j))));
//point3.X = 230 / 2 + 80;
//point3.Y = 230 / 2 + 30;
//point4.X = (int)(230 / 2 + 80 + 230 / 2 * System.Math.Sin(1.57 + j));
//point4.Y = (int)(230 / 2 + 30 - 230 / 2 * System.Math.Cos(1.57 + j)); p1.Color = Color.Blue;
g.DrawLine(p1, point3, point4);
j = j + 0.5;
p1.Dispose();
g.Dispose();
} 也就是说,能重用的对象,尽量重用;对象使用完后,能释放的尽量释放。
曾经用这样的方法做坦克大战,刷新率达到了0.04秒,也不闪烁。
双缓冲我写过个例子9L ,还有别人的一些方法
http://topic.csdn.net/u/20081029/21/1619cabb-61b4-4344-b776-4bdbb5d85936.html
添加this.SetStyle(ControlStyles.AllPaintingInWmPaint,true);
this.SetStyle(ControlStyles.DoubleBuffer,true);
this.SetStyle(ControlStyles.UserPaint,true);这三句话是表明每次先在缓存中画好控件,再刷新,这样便不会闪烁了