C#画图的时候 如何实现不闪烁呢?

KevinCEC 2007-11-05 05:15:31
1. 我先在Paint 把 所有要画的内容画到 m_bmpBackLine01;//Bitmap m_bmpBackLine01
2. this.CreateGraphics().DrawImage(m_bmpBackLine01, 15, 0);//画到form上
3. 定时器1000ms 定时刷新 调用 this.Invalidate();

结果闪烁很厉害,添加了
this.SetStyle(ControlStyles.AllPaintingInWmPaint, true);
this.SetStyle(ControlStyles.OptimizedDoubleBuffer, true);
this.SetStyle(ControlStyles.UserPaint, true);
this.SetStyle(ControlStyles.ResizeRedraw, true);

还是一样 感觉更严重一些. 图的整个屏幕.

...全文
302 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
KevinCEC 2007-11-06
  • 打赏
  • 举报
回复
放在PictureBox里 真的不闪了, 但是我没有设置什么属性, 不知道属性怎么设置才是最好的啊?
臭脚大仙 2007-11-06
  • 打赏
  • 举报
回复
遇到过这样的问题,忘记是怎么解决的了。
BookSirSwordsMan 2007-11-06
  • 打赏
  • 举报
回复
放在PictureBox里 真的不闪了, 但是我没有设置什么属性, 不知道属性怎么设置才是最好的啊?
--------------------------------------------------------------
你自己画的时候,虽然有设置了双缓冲属性,但还是直接在上面画的,所以。。。

还有一种双缓冲是在内存中画好的时候再贴出来,我想PictureBox应该也是这样来做的
北京的雾霾天 2007-11-06
  • 打赏
  • 举报
回复
this.SetStyle(ControlStyles.AllPaintingInWmPaint, true);
this.SetStyle(ControlStyles.OptimizedDoubleBuffer, true);
this.SetStyle(ControlStyles.UserPaint, true);
this.SetStyle(ControlStyles.ResizeRedraw, true);

使用上面的设置后,不能通过this.CreateGraphics()来建立Graphics对象,而是通过OnPaint方法或paint事件里的e.Graphics
来绘制图像,否则没有效果或效果不明显。
例如:


protected override void OnPaint(PaintEventArgs e)
{
e.Graphics.DrawImage(m_bmpBackLine01, 15, 0);//画到form上
base.OnPaint(e);
}
wzd24 2007-11-06
  • 打赏
  • 举报
回复
自画控件一定不要从UserControl继承,而要从Control继承。PictureBox不闪烁的原因就是它是从Control继承的。
王集鹄 2007-11-05
  • 打赏
  • 举报
回复
DoubleBuffered = true;
harryheart 2007-11-05
  • 打赏
  • 举报
回复
用BufferedGraphics?
cpio 2007-11-05
  • 打赏
  • 举报
回复

用PictureBox吧,直接在上面画就行,把它的属性设置一下就不闪烁了

110,534

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧