# Set background label to transparent?

**URL:** <https://www.ruby-forum.com/t/set-background-label-to-transparent/120582>\
**Category:** wxRuby\
**Created:** [November 18, 2007, 8:39pm UTC](https://www.ruby-forum.com/t/set-background-label-to-transparent/120582 "2007-11-18T20:39:27Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![blitzer](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/ecae2f/32.png) [@blitzer](https://www.ruby-forum.com/u/blitzer)\
**Post date:** [November 18, 2007, 8:39pm UTC](https://www.ruby-forum.com/t/set-background-label-to-transparent/120582/1 "2007-11-18T20:39:27Z")

</div>

I just use wxRuby and I have problem

I use background image on my app and when I create label it seem look  
background of label is gray, how can I change it into transparent???

---

<div class="post-metadata">

**Author:** ![blitzer](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/ecae2f/32.png) [@blitzer](https://www.ruby-forum.com/u/blitzer)\
**Post date:** [November 19, 2007, 10:43am UTC](https://www.ruby-forum.com/t/set-background-label-to-transparent/120582/2 "2007-11-19T10:43:36Z")

</div>

Pat K. wrote:

> I just use wxRuby and I have problem
> 
> I use background image on my app and when I create label it seem look  
> background of label is gray, how can I change it into transparent???

Can you show us the code you’re using here, and tell us what platform  
(Win/Linux/Mac) you’re using.

thanks  
alex

---

<div class="post-metadata">

**Author:** ![blitzer](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/ecae2f/32.png) [@blitzer](https://www.ruby-forum.com/u/blitzer)\
**Post date:** [November 19, 2007, 6:09pm UTC](https://www.ruby-forum.com/t/set-background-label-to-transparent/120582/3 "2007-11-19T18:09:27Z")

</div>

my code is

@label1 = StaticText.new(@picturebox2, -1, ‘Calculator’,  
Point.new(168,38), Size.new(213, 39))  
@label1.set\_foreground\_colour(Colour.new(255, 0, 255))  
@label1.set\_font(Font.new(15, FONTFAMILY\_DEFAULT, BOLD,  
FONTWEIGHT\_NORMAL, FALSE, ‘Kristen ITC’))

@picturebox2 is image background that I add to Panel  
I set like this and output it’s can work completely but background of  
‘Calculator’ label is gray and other label be the same :’(

see my attachment picture

---

<div class="post-metadata">

**Author:** ![blitzer](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/ecae2f/32.png) [@blitzer](https://www.ruby-forum.com/u/blitzer)\
**Post date:** [November 19, 2007, 6:10pm UTC](https://www.ruby-forum.com/t/set-background-label-to-transparent/120582/4 "2007-11-19T18:10:05Z")

</div>

ah I use in Window

---

<div class="post-metadata">

**Author:** ![blitzer](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/ecae2f/32.png) [@blitzer](https://www.ruby-forum.com/u/blitzer)\
**Post date:** [November 19, 2007, 6:27pm UTC](https://www.ruby-forum.com/t/set-background-label-to-transparent/120582/5 "2007-11-19T18:27:21Z")

</div>

Pat K. wrote:

> @label1 = StaticText.new(@picturebox2, -1, ‘Calculator’,  
> Point.new(168,38), Size.new(213, 39))  
> @label1.set\_foreground\_colour(Colour.new(255, 0, 255))  
> @label1.set\_font(Font.new(15, FONTFAMILY\_DEFAULT, BOLD,  
> FONTWEIGHT\_NORMAL, FALSE, ‘Kristen ITC’))
> 
> @picturebox2 is image background that I add to Panel  
> I set like this and output it’s can work completely but background of  
> ‘Calculator’ label is gray and other label be the same :’(

On Windows at least, StaticText always draws its background in the theme  
background colour.

Instead of using StaticText, I would suggest drawing the text directly  
onto the bitmap using a DC (DeviceContext), inside an evt\_paint event.  
Use draw\_bitmap to paint the bitmap onto the frame, then draw\_text to  
draw the text atop it.

The simplest example of this can be found in the dialogs/dialogs.rb  
sample - search for on\_paint method.

hth  
alex
