UI with Transparent Background doesn't show the Next Immediate Layer - c#

If we set the background of any UI as transparent, it doesn't show what's beneath that, meaning any UI or containers. Instead, it shows the default background of the Form, the lowermost, that is.
How do I get around this transparency problem?

This is by design, unfortunately:
http://support.microsoft.com/kb/943454
Transparent controls in WinForms are transparent relative to their
parent, not to other controls. Transparency in WinForms is more akin
to camouflage than true transparency. A transparent control doesn’t
actually let you see the control behind it through the form. It asks
its parent to draw its own background on the "transparent" control.
This is why a transparent control shows the form behind it, but covers
up any other controls.
There is some code in the link that demonstrates a work around.

Windows Forms controls do not support true transparency. The background of a transparent Windows Forms control is painted by its parent.
To give your control a transparent backcolor
This will enable your control to support a transparent backcolor.
SetStyle(ControlStyles.SupportsTransparentBackColor, true);
this.BackColor = Color.Transparent;

Related

how to create transparent label in toolbox in winforms

I have a System.Windows.Forms.ToolStrip which contains a Label.
The ToolStrip has a special fancy background. But the label is just gray.
It's not possible to use transparency because the parent of ToolStrip is a form. Also it's not possible to change the parent, because the collection of Controls in ToolStrip is read only.
Is it possible to create a Label that is transparent and which has a ToolStrip parent?
Give the following a shot.
Set the backcolor of the label to Color.Transparent.
Then you have to add the label directly to the control collection of the control of which you want the label to appear transparent on top of.
If you just delete the assigned background color of the ToolStripLabel then it ought to inherit the background of its parent ToolStrip. I use a custom ToolStripRenderer to draw a customized background for tool strips, and my labels do not need any special handling in order to inherit the parent's background. Just make sure you aren't trying to assign a background color.

Transparent controls in .NET

I have a problem with:
BackColor = Color.Transparent;
It's not working correctly. I have a form with a blue background, and a picturebox with a picture loaded in it. It's not actually taking what's in the picture, but rather - the form's background color. Please tell me there's a simple way to go around this?
What you see in the following screenshot is a custom usercontrol with it's backColor set to transparent, on top of a picture, in a form with a blue background.
I need the usercontrol to display what's UNDER it, as real transparency, it should be showing the gradient and part of the image.
Try setting the picture box to be the parent of the custom user control.
myControl.Parent = this.myPictureBox;
Try calling "SetStyle(ControlStyles.SupportsTransparentBackColor, true);" on your user control constructor.
more details at: http://msdn.microsoft.com/en-us/library/wk5b13s4(v=vs.90).aspx

WinForms draw a non transparent string into a transparent form

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.
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.

Shadow to windows form

I am working in C# Windows Forms Application
I want to make shadow of my form, so I have taken a image having shadow and set it as Form's Background image and also set TransparentKey to Form's BackColor i.e. Control Color, so that it will transparent the area which contains Control color and FormBorderStyle to None.
My problem is that I am not getting the shadow transparent, it is of Control Color.
Updated: I also want to change shape of my form
I would use this technique instead; it worked beautifully for me.
Drop shadow in Winforms Controls?
Update:
Changing the shape of a form is easier than you'd think.
Follow this tutorial: http://www.codegod.de/WebAppCodeGod/creating-custom-shapes-for-forms-in-windows-forms-AID377.aspx

How to make the form completely transparent

I already made the background transparent but there is still some part left from the group box. How do I make those transparent also?
The blank line are what I want it to be transparent. It should give you the picture of what I want. Thanks.
And don't even ask what are the password for, all of them are just dummies :)
If you want to see and edit the code, here
That's just how the GroupBox control works. The Background property of that control includes the area that your screenshot points to. If you wanted to do a workaround for it, you should set the GroupBox background to be transparent as well, and draw a white box behind it, encompassing only the area you want to be white.
Form.Opacity doesn't work for you?
What is the GroupBox's parent container? Is it a Form or a Panel? Is that element also set to transparent? As a test I made a GroupBox and placed it on top of (inside) a Panel. I changed the background color of the Panel to red and the background color of the GroupBox to transparent and those ares of the GroupBox are properly transparent. My suggestion is to look at the parent container.
Also the GroupBox label may become hard to read in some cases, once the top strip is transparent.

Categories

Resources