2
votes

I'm building an app in which I have to show a semitransparent form. I need to draw some text on that form too, to let the user know some info. However, the strings I draw are also semitransparent and are difficult to read. I was wondering if there is a way to draw a non transparent string into a semitransparent form. I'm using .NET 4.0, C# and WinForms technology. For the moment I use the DrawString method on the Graphics form, but using a Label had no effect at all tho. Browsing StackOverflow I found this How do I make my form transparent, but what I draw on it not? but it refers to WPF, and I'm using plain old WinForms.

Cheers.

1
You can have a partially opaque window, makes the text opaque too as you found out, or a fully transparent window with non-opaque text using the TransparencyKey property. If you want both then you need a sandwich of both. Two windows on top of each other. Display the 2nd window with the Show(owner) overload.Hans Passant
Can you paste the code you use to make the form semi-transparent?Otiel
To make the form semi transparent I just set the opacity property to 10%brafales
May be this article will be helpfull?DmitryG

1 Answers

1
votes

This might help you - it will give you a fully transparent form with non-transparent text:

in InitializeComponent:

SetStyle(ControlStyles.SupportsTransparentBackColor, true);
TransparencyKey = BackColor;
ShowInTaskbar = false;
FormBorderStyle = FormBorderStyle.None;

in OnPaint override:

g.DrawString(...) // Use some SolidBrush.

However, if you don't want fully transparent form (this won't sound nice but should work), then you can use TWO forms: One with semi transparent background, no text. Other one (on top of the previous one) with fully transparent background and non-transparent text. You can bind location, size and visibility of one form to another to keep them in synch.