2

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.

asked Nov 5, 2011 at 21:10
7
  • In VB: stackoverflow.com/questions/518020/… Commented Nov 5, 2011 at 21:16
  • 4
    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. Commented Nov 5, 2011 at 21:42
  • Can you paste the code you use to make the form semi-transparent? Commented Nov 5, 2011 at 21:49
  • To make the form semi transparent I just set the opacity property to 10% Commented Nov 5, 2011 at 22:29
  • May be this article will be helpfull? Commented Nov 6, 2011 at 20:15

1 Answer 1

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.

answered Nov 10, 2011 at 22:50
Sign up to request clarification or add additional context in comments.

1 Comment

Yes, that's the approach I took as someone commented on the original post. Thanks mate.

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.