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.
-
In VB: stackoverflow.com/questions/518020/…Andrey Sboev– Andrey Sboev2011年11月05日 21:16:10 +00:00Commented Nov 5, 2011 at 21:16
-
4You 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– Hans Passant2011年11月05日 21:42:42 +00:00Commented Nov 5, 2011 at 21:42
-
Can you paste the code you use to make the form semi-transparent?Otiel– Otiel2011年11月05日 21:49:19 +00:00Commented Nov 5, 2011 at 21:49
-
To make the form semi transparent I just set the opacity property to 10%brafales– brafales2011年11月05日 22:29:21 +00:00Commented Nov 5, 2011 at 22:29
-
May be this article will be helpfull?DmitryG– DmitryG2011年11月06日 20:15:35 +00:00Commented Nov 6, 2011 at 20:15
1 Answer 1
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.