# Set the background to a bitmap

**URL:** <https://www.ruby-forum.com/t/set-the-background-to-a-bitmap/157614>\
**Category:** wxRuby\
**Created:** [January 13, 2009, 6:55pm UTC](https://www.ruby-forum.com/t/set-the-background-to-a-bitmap/157614 "2009-01-13T18:55:26Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![softf5ajivanet](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/9f8e36/32.png) [@softf5ajivanet](https://www.ruby-forum.com/u/softf5ajivanet)\
**Post date:** [January 13, 2009, 6:55pm UTC](https://www.ruby-forum.com/t/set-the-background-to-a-bitmap/157614/1 "2009-01-13T18:55:26Z")

</div>

Hi,

any ideas whether you can set the background of a dialog to use an  
image?

---

<div class="post-metadata">

**Author:** ![softf5ajivanet](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/9f8e36/32.png) [@softf5ajivanet](https://www.ruby-forum.com/u/softf5ajivanet)\
**Post date:** [January 13, 2009, 8:18pm UTC](https://www.ruby-forum.com/t/set-the-background-to-a-bitmap/157614/2 "2009-01-13T20:18:07Z")

</div>

I have a WxRuby app running on Windows and I want to try to port it to  
the  
new Ruby 1.9.1. I see wxruby-ruby19-1.9.8 gems for Darwin and Linux,  
but  
not for Windows. Is wxruby-ruby19-1.9.8 available for Windows yet? If  
not,  
when will it be available? And how stable is it?

Thanks,  
Eric R.

---

<div class="post-metadata">

**Author:** ![softf5ajivanet](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/9f8e36/32.png) [@softf5ajivanet](https://www.ruby-forum.com/u/softf5ajivanet)\
**Post date:** [January 13, 2009, 8:48pm UTC](https://www.ruby-forum.com/t/set-the-background-to-a-bitmap/157614/3 "2009-01-13T20:48:12Z")

</div>

John G. wrote:

> any ideas whether you can set the background of a dialog to use an  
> image?

Use evt\_erase\_background, which is meant for this:  
[http://wxruby.rubyforge.org/doc/eraseevent.html](http://wxruby.rubyforge.org/doc/eraseevent.html)

The example below just fills with colour, but you could replace the call  
to gradient\_fill\_linear with one to DC#draw\_bitmap or whatever other  
drawing/painting code yoou wanted. Please, just don’t do anything as  
eyesore as this …

alex  
\_\_  
require ‘wx’

class BackgroundDialog \< Wx::Dialog  
def initialize(parent)  
super(parent, :title =\> “dialog with background”)  
Wx::TextCtrl.new(self, :value =\> ‘foo’, :pos =\> [50, 50])  
evt\_erase\_background :on\_erase\_background  
end

def on\_erase\_background(evt)  
# Use the event’s DC object to draw whatever background you want  
evt.dc.gradient\_fill\_linear( client\_rect,  
Wx::RED, Wx::BLACK, Wx::NORTH )  
end  
end

Wx::App.run do  
frame = Wx::Frame.new(nil, :title =\> ‘frame’)  
frame.show  
BackgroundDialog.new(frame).show  
end

---

<div class="post-metadata">

**Author:** ![softf5ajivanet](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/9f8e36/32.png) [@softf5ajivanet](https://www.ruby-forum.com/u/softf5ajivanet)\
**Post date:** [January 13, 2009, 11:35pm UTC](https://www.ruby-forum.com/t/set-the-background-to-a-bitmap/157614/4 "2009-01-13T23:35:06Z")

</div>

Eric R. wrote:

> I have a WxRuby app running on Windows and I want to try to port it to the  
> new Ruby 1.9.1. I see wxruby-ruby19-1.9.8 gems for Darwin and Linux, but  
> not for Windows. Is wxruby-ruby19-1.9.8 available for Windows yet? If not,  
> when will it be available?

We’ll definitely have a ruby19 gem available for Windows for the  
upcoming 2.0 release (next week or so). Whether we offer both mingw and  
mswin32 for Ruby 1.9.1 is not yet finalised, but in practice they’re  
interchangeable. There will certainly be mingw as that’s the direction  
the OCI is going in (for good reasons, IMHO).

> And how stable is it?

Very. wxRuby has supported ruby 1.9 for a year now, and I switched over  
mainline dev of my app to it a few months ago. There are also a lot of  
changes in SVN HEAD which make it considerably more stable generally  
than the current beta releaes, 1.9.9.

alex

---

<div class="post-metadata">

**Author:** ![softf5ajivanet](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/9f8e36/32.png) [@softf5ajivanet](https://www.ruby-forum.com/u/softf5ajivanet)\
**Post date:** [January 15, 2009, 2:36pm UTC](https://www.ruby-forum.com/t/set-the-background-to-a-bitmap/157614/5 "2009-01-15T14:36:44Z")

</div>

Thanks Alex, I got the dialog to use a background image eventually, did  
this with WxRuby 1.9.9 on Windows XP and it works (doesn’t on OSX, but  
don’t need it to).

def initialize(title)  
…  
evt\_erase\_background :on\_erase\_background  
end

def on\_erase\_background(evt)  
b\_splash\_bmp = Wx::Bitmap.new(‘images/background.gif’,  
BITMAP\_TYPE\_GIF)  
evt.dc.draw\_bitmap(b\_splash\_bmp, 0, 0, false)  
end

---

<div class="post-metadata">

**Author:** ![softf5ajivanet](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/9f8e36/32.png) [@softf5ajivanet](https://www.ruby-forum.com/u/softf5ajivanet)\
**Post date:** [January 13, 2009, 10:17pm UTC](https://www.ruby-forum.com/t/set-the-background-to-a-bitmap/157614/6 "2009-01-13T22:17:55Z")

</div>

Thanks again Alex, will give that a go tomorrow and see how things turn  
out.

Appreciate this
