# Black background using paint\_buffered

**URL:** <https://www.ruby-forum.com/t/black-background-using-paint-buffered/135587>\
**Category:** wxRuby\
**Created:** [April 23, 2008, 12:24pm UTC](https://www.ruby-forum.com/t/black-background-using-paint-buffered/135587 "2008-04-23T12:24:39Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![awarberg](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/b5ac83/32.png) [@awarberg](https://www.ruby-forum.com/u/awarberg)\
**Post date:** [April 23, 2008, 12:24pm UTC](https://www.ruby-forum.com/t/black-background-using-paint-buffered/135587/1 "2008-04-23T12:24:39Z")

</div>

Hi,

To avoid flickering during screen updates in a Frame on Windows I  
recently switched from

paint do | dc |  
#…  
end

to

paint\_buffered do | dc |  
#…  
end

The background colour of the Frame is set to WHITE, which is respected  
under paint, but is replaced by BLACK under paint\_buffered.

The painting jobs seems fine, though all my black lines become invisible  
😛

Is there something I can do to sort this out? Perhaps supply my own  
buffer…

Thank you!

Regards, Andreas

---

<div class="post-metadata">

**Author:** ![awarberg](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/b5ac83/32.png) [@awarberg](https://www.ruby-forum.com/u/awarberg)\
**Post date:** [April 23, 2008, 12:39pm UTC](https://www.ruby-forum.com/t/black-background-using-paint-buffered/135587/2 "2008-04-23T12:39:55Z")

</div>

Andreas W. wrote:

> #…

Yes, you can pass your own buffer as an optional argument to  
paint\_buffered. It should be a Wx::Bitmap of the appropriate height and  
width.

I will see if the ruby code that does paint\_buffered could make the  
bitmap background match the window’s.

a

---

<div class="post-metadata">

**Author:** ![awarberg](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/b5ac83/32.png) [@awarberg](https://www.ruby-forum.com/u/awarberg)\
**Post date:** [April 23, 2008, 12:45pm UTC](https://www.ruby-forum.com/t/black-background-using-paint-buffered/135587/3 "2008-04-23T12:45:51Z")

</div>

Dang you Alex,

You beat me to it. 😛 Actually, another suggestion, would be to use  
Wx::DC#draw\_rectangle(), in which you set the Pen and Brush with the  
color  
you want to use.

Simple Example (Not Tested):

`
pen = Wx::Pen.new(Wx::WHITE)
brush = Wx::Brush.new()
brush.colour(Wx::WHITE)
dc.set_pen(pen)
dc.set_brush(brush)
dc.draw_rectangle(0,0,self.width,self.height)
… do your drawing here …
`

L8ers,

---

<div class="post-metadata">

**Author:** ![awarberg](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/b5ac83/32.png) [@awarberg](https://www.ruby-forum.com/u/awarberg)\
**Post date:** [April 23, 2008, 12:55pm UTC](https://www.ruby-forum.com/t/black-background-using-paint-buffered/135587/4 "2008-04-23T12:55:38Z")

</div>

Mario S. wrote:

> pen = Wx::Pen.new(Wx::WHITE)  
> brush = Wx::Brush.new()  
> brush.colour(Wx::WHITE)
> 
> dc.set\_pen(pen)  
> dc.set\_brush(brush)  
> dc.draw\_rectangle(0,0,self.width,self.height)
> 
> … do your drawing here …

Thanks for this workaround. I now have flicker free updates AND a white  
background 🙂

I’m looking forward to your update, Alex.

Thanks guys - I’m enjoying wxruby 🙂
