Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I make my form transparent, but what I draw on it not?

I tried setting the opacity of my form to 50%, and then drawing a string on it. It seems that the string I draw on it also has an opacity of 50%. How would I draw a non transparent string , but let the form background show through 50%?

Would also be willing to do this in WPF if it is possible, but I would need explicit instructions or an example project as I have never done it before.

To clarify, I want the form background to be a black 80% opaque to what is underneath, and then I want to draw text, etc.. on it and have it appear 100% opaque.

like image 217
esac Avatar asked Oct 09 '09 04:10

esac


People also ask

How do I make a div transparent but not text?

The percentage of opacity is calculated as Opacity% = Opacity * 100 To set the opacity only to the background and not the text inside it. It can be set by using the RGBA color values instead of the opacity property because using the opacity property can make the text inside it fully transparent element.

How do I make a background transparent in HTML?

Example explained. First, we create a <div> element (class="background") with a background image, and a border. Then we create another <div> (class="transbox") inside the first <div>. The <div class="transbox"> have a background color, and a border - the div is transparent.

How do I change the opacity of a shape in Word?

Right-click, and on the context menu, select Format Shape. In the Format Shape pane, set the Transparency slider to the percentage of transparency that you want.

How do you make a background transparent in CSS?

To set the opacity of a background, image, text, or other element, you can use the CSS opacity property. Values for this property range from 0 to 1. If you set the property to 0, the styled element will be completely transparent (ie. invisible).


2 Answers

This is very easily done in WPF:

  1. Set WindowStyle="None" on the Window (note: this is required, you cannot have Transparency and the standard windows chrome)
  2. Set AllowsTransparency="True" on the Window
  3. Set a Background on the Window using a brush with transparency, such as Background="#AAFFFFFF"

Here's a quick sample:

<Window
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
Height="300" Width="300" AllowsTransparency="True" Background="#AAFFFFFF" WindowStyle="None">
<Grid>
    <TextBlock HorizontalAlignment="Center" VerticalAlignment="Center" FontSize="20" FontWeight="Bold">Hello World!</TextBlock>
</Grid>

Now obviously, since you've disabled the standard Windows chrome, you will need to supply your own button to close/minimize/maximize/drag the window. You can do this pretty easily yourself or you could look into purchasing something like Blendables which comes with a "Chromeless Window" control that you could use.

like image 59
Drew Marsh Avatar answered Oct 09 '22 15:10

Drew Marsh


You can use the TransparencyKey.

http://msdn.microsoft.com/en-us/library/system.windows.forms.form.transparencykey.aspx

like image 31
David Avatar answered Oct 09 '22 16:10

David