>>>>老问题,关于图片显示刷新闪烁问题???

lz_0618 2009-07-22 09:08:13
用C#自带的控件PictureBox,在OnPaint中划线,刷新(Invalidate)时不闪烁,但我从Control继承的控件中,在底图上划线刷新(Invalidate)时却闪烁??
1,在自定义控件中图片是放在控件本身的BackgroundImage上的,这也闪烁??
2,若再定义一个Image属性,通过双缓冲绘图时,也一样闪烁??

protected override void OnPaint(PaintEventArgs pe)
{
// Calling the base class OnPaint
base.OnPaint(pe);
ReDrawControl(pe.Graphics);
}
private void ReDrawControl(Graphics graphics)
{

//双缓冲绘图
Image BackImage = new Bitmap(Width, Height);
Graphics g = Graphics.FromImage(BackImage);

g.SmoothingMode = SmoothingMode.HighQuality; //高质量
g.PixelOffsetMode = PixelOffsetMode.HighQuality; //高像素偏移质量

DrawBackImage(g);
graphics.DrawImage(BackImage, 0, 0, Width, Height);

}
...全文
139 1 打赏 收藏 转发到动态 举报
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
北京的雾霾天 2009-07-22
  • 打赏
  • 举报
回复
1:构造函数中添加如下代码:
public drawControl()
{
this.SetStyle(ControlStyles.AllPaintingInWmPaint | ControlStyles.UserPaint | ControlStyles.OptimizedDoubleBuffer, true);
}

2:在OnPaint中正常的绘制,不需要再建立一个Bitmap。
3:如果需要立即绘制只需要调用Control.Invalidate。最好不要在OnPaint中调用此方法。

110,534

社区成员

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

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

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