# Transparency on WxStaticText background?

**URL:** <https://www.ruby-forum.com/t/transparency-on-wxstatictext-background/182159>\
**Category:** wxRuby\
**Created:** [January 23, 2010, 5:25pm UTC](https://www.ruby-forum.com/t/transparency-on-wxstatictext-background/182159 "2010-01-23T17:25:10Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![elricstorm](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/da6949/32.png) [@elricstorm](https://www.ruby-forum.com/u/elricstorm)\
**Post date:** [January 23, 2010, 5:25pm UTC](https://www.ruby-forum.com/t/transparency-on-wxstatictext-background/182159/1 "2010-01-23T17:25:10Z")

</div>

I’ve painted my gui and I like the background mesh for my gui. I want  
my static text to inherit the background paint of my gui. Instead I get  
a gray background around the static text. Here’s a picture:

[![](https://i780.photobucket.com/albums/yy89/jdezenzio/example_background.jpg) ](https://i780.photobucket.com/albums/yy89/jdezenzio/example_background.jpg)

How do I make it so that the background of the StaticText is  
transparent?

Thanks.

---

<div class="post-metadata">

**Author:** ![elricstorm](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/da6949/32.png) [@elricstorm](https://www.ruby-forum.com/u/elricstorm)\
**Post date:** [January 23, 2010, 9:58pm UTC](https://www.ruby-forum.com/t/transparency-on-wxstatictext-background/182159/2 "2010-01-23T21:58:05Z")

</div>

On 23/01/2010 16:25, Alpha B. wrote:

> I’ve painted my gui and I like the background mesh for my gui. I want  
> my static text to inherit the background paint of my gui. Instead I get  
> a gray background around the static text. Here’s a picture:
> 
> [http://i780.photobucket.com/albums/yy89/jdezenzio/example\_background.jpg](http://i780.photobucket.com/albums/yy89/jdezenzio/example_background.jpg)
> 
> How do I make it so that the background of the StaticText is  
> transparent?

Hard to test without the code, but have you tried setting the DC’s brush  
to TRANSPARENT?

eg

dc.brush = Wx::TRANSPARENT\_BRUSH

Also, take a look into evt\_erase\_background which is specifically  
designed for drawing bitmaps as a background on controls.

hth  
alex

---

<div class="post-metadata">

**Author:** ![elricstorm](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/da6949/32.png) [@elricstorm](https://www.ruby-forum.com/u/elricstorm)\
**Post date:** [January 23, 2010, 10:26pm UTC](https://www.ruby-forum.com/t/transparency-on-wxstatictext-background/182159/3 "2010-01-23T22:26:46Z")

</div>

Hi Alex,

Basically, the control was created inside of DialogBlocks and extended  
into  
a module. The code appears like so:

@title\_st\_one = finder.call(“title\_st\_one”)  
@title\_st\_one.extend(StaticTextControls)

I then have a module for:

module StaticTextControls  
self.evt\_erase\_background do |event|  
self.paint do |dc|  
dc.brush = Wx::TRANSPARENT\_BRUSH  
# ??  
end  
end  
end

I can extend into this module using @title\_st\_one.repaint\_my\_control and  
I  
have some of the code above. I’m not wanting to paint a bitmap onto  
this  
control. I just want this control to become transparent so that the  
underlying bitmap which is already painted onto the parent frame shows.

Example:

Main Frame (already painted with bitmap)  
– StaticTextControl (should be transparent so that it shows the Main  
Frame)

I’ll read up on evt\_erase\_background but I’m not sure how to use the  
dc.brush code you supplied with this example. Any further help would be  
appreciated.

Sincerely,

Joel D.  
Website Bio: [http://jdezenzio.com/](http://jdezenzio.com/)  
Rails Production Sites: [http://ncaastatpages.com](http://ncaastatpages.com)

---

<div class="post-metadata">

**Author:** ![elricstorm](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/da6949/32.png) [@elricstorm](https://www.ruby-forum.com/u/elricstorm)\
**Post date:** [January 24, 2010, 12:46am UTC](https://www.ruby-forum.com/t/transparency-on-wxstatictext-background/182159/4 "2010-01-24T00:46:18Z")

</div>

So, I took the approach I believe you were trying to get me to do. I  
believe I found a partial answer but I’m still stumped.

The partial answer is that I can’t use a StaticText control and achieve  
transparency. Windows will force the background to the current theme  
and you can’t get around that without drawing the text on the canvas  
instead.

So, I removed the StaticText control and created a small panel using the  
same class and variable name.

Here’s what I have:

module StaticTextControls  
def paint\_text(message)  
self.evt\_erase\_background do |event|  
self.paint do |dc|  
dc.set\_background\_mode(Wx::TRANSPARENT)  
dc.set\_brush(Wx::TRANSPARENT\_BRUSH)  
dc.draw\_text(message, 5, 5)  
end  
end  
end  
end

and I call it using the following extension:

@title\_st\_one.paint\_text(“Test for Paint”)

And here’s what it shows:

[![](https://i780.photobucket.com/albums/yy89/jdezenzio/example_background2.jpg) ](https://i780.photobucket.com/albums/yy89/jdezenzio/example_background2.jpg)

As you can see, the text is now painted on the panel and the panel is  
the gray looking rectangle behind the text.

The problem I have now is how do I make the panel itself transparent so  
that the window behind it (the gradient steel blue I created) shows?  
Sure, I can paint a bitmap on the panel but I don’t want to paint a  
bitmap image. I just want to force it to be transparent.

Any ideas on how to do this?

Thanks.
