使用双重缓冲,背景色变黑的问题。。。

chenbin0522 2010-10-14 09:57:30
protected override void OnPaint(PaintEventArgs e)
{
using (BufferedGraphicsContext bufferContext = new BufferedGraphicsContext())
{
using (BufferedGraphics grafx = bufferContext.Allocate(e.Graphics, base.ClientRectangle))
{
grafx.Graphics.PixelOffsetMode = PixelOffsetMode.HighQuality;
grafx.Graphics.SmoothingMode = SmoothingMode.AntiAlias;

// 画线操作。。。。

grafx.Render(e.Graphics);
}
}
}
用到双缓冲,会将背景刷成黑色,如果能做到双缓冲并且透明?
...全文
114 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
chenbin0522 2010-10-26
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 gxingmin 的回复:]

在构造函数里加上
this.SetStyle(ControlStyles.DoubleBuffer, true); //双缓冲
this.SetStyle(ControlStyles.UserPaint, true);
this.SetStyle(ControlStyles.AllPaintingInWmPaint, true);


protected override void ……
[/Quote]

我以前的代码是这样写的,虽然透明但是会闪的厉害。。。
lyl1599 2010-10-14
  • 打赏
  • 举报
回复
学习了
HaveOneDream 2010-10-14
  • 打赏
  • 举报
回复
grafx.Clear(Color.White);
背景设置成白色的
透明的?应该没有这种
gxingmin 2010-10-14
  • 打赏
  • 举报
回复
在构造函数里加上
this.SetStyle(ControlStyles.DoubleBuffer, true); //双缓冲
this.SetStyle(ControlStyles.UserPaint, true);
this.SetStyle(ControlStyles.AllPaintingInWmPaint, true);


protected override void OnPaint(PaintEventArgs e)
{
e.Graphics.PixelOffsetMode = PixelOffsetMode.HighQuality;
e.Graphics.SmoothingMode = SmoothingMode.AntiAlias;

// 画线操作。。。。

e.Render(e.Graphics);
}
oeasypeasy 2010-10-14
  • 打赏
  • 举报
回复
  this.SetStyle(
ControlStyles.OptimizedDoubleBuffer |
ControlStyles.ResizeRedraw, true);

this.SetStyle(ControlStyles.DoubleBuffer, true);
this.SetStyle(ControlStyles.UserPaint, true);
this.SetStyle(ControlStyles.AllPaintingInWmPaint, true);

加载在构造函数中。。试试,

110,536

社区成员

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

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

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