我点击一个按钮,目的是重新显示背景图片(请不要问为什么这样做,只是想法而已)
private void Button1_Click(....)
{
panel1.BackgroundImage=Image.FromFile("d:\\aa.jpg");}
我发现点击按钮时,图片闪烁得太厉害了,后来在构造中加入如下代码:
this.SetStyle(ControlStyles.AllPaintingInWmPaint, true);
this.SetStyle(ControlStyles.UserPaint, true);
this.SetStyle(ControlStyles.OptimizedDoubleBuffer, true);
也不起作用?这是为什么、怎么解决呢?
private void Button1_Click(....)
{
panel1.BackgroundImage=Image.FromFile("d:\\aa.jpg");}
我发现点击按钮时,图片闪烁得太厉害了,后来在构造中加入如下代码:
this.SetStyle(ControlStyles.AllPaintingInWmPaint, true);
this.SetStyle(ControlStyles.UserPaint, true);
this.SetStyle(ControlStyles.OptimizedDoubleBuffer, true);
也不起作用?这是为什么、怎么解决呢?
this.SetStyle(ControlStyles.UserPaint, true);
this.SetStyle(ControlStyles.AllPaintingInWmPaint, true);
是这三个
this.SetStyle(ControlStyles.DoubleBuffer, true)
只有
this.SetStyle(ControlStyles.OptimizedDoubleBuffer, true);
解决的方法是使用双缓冲技术。
我知道以前C++ builder里的图片框可以把一个属性(好像叫DoubleBuffer)设为True,就可以打开双缓冲了。C#里有没有我不知道。
我这个人比较懒!有问题懒得问别人都是去MSDN或GOOGLE上查!我建议LZ多使用MSDN和GOOGLEMSDN原话!
DoubleBuffer
如果为 true,则绘制在缓冲区中进行,完成后将结果输出到屏幕上。双重缓冲区可防止由控件重绘引起的闪烁。要完全启用双重缓冲,还必须将 UserPaint 和 AllPaintingInWmPaint 样式位设置为 true。
this.SetStyle(ControlStyles.AllPaintingInWmPaint, true);
this.SetStyle(ControlStyles.UserPaint, true);
this.SetStyle(ControlStyles.OptimizedDoubleBuffer, true);
但是我加上后不起作用,百思不得其解,希望各位高手拉一下下哦
this.SetStyle(ControlStyles.UserPaint, true);
this.SetStyle(ControlStyles.AllPaintingInWmPaint, true);
这三个才是启动双缓冲呢
this.SetStyle(ControlStyles.UserPaint, true);
this.SetStyle(ControlStyles.OptimizedDoubleBuffer, true);这三行代码算不上真正意义上的双缓冲...虽然这三行代码也曾经帮我解决过一些图片闪烁的问题..
你可以参考这个文章
利用GDI+的双缓冲技术来提高绘图效率
http://blog.joycode.com/5drush/articles/10701.aspx