Transparent background on form - c#

I have tried many ways to have a transparent background on my form. Transparency key does work, but problems arise when you put images that have opacity. I tried to override OnPaintBackground which only removed my background image. And I tried the SetStyle method.

Assuming you are using windows forms, try:
this.TransparencyKey = Color.Red;
this.BackColor = Color.Red;
when you have a color on the form which is the same as your transparency key, then it will be transparent. on the other hand, by that the red color is assigned for transparency only, you won't be able to use it.
(and this refers to the form)

You can set opacity of the form.100% is default for Windows form and lower values are more transparent.

Related

I have a picture box with an image without background but it only takes the color of the form as background

I'm doing the table game battleship, by moving pictures boxes with the mouse, the problem is that all the picture boxes that I have contain an image without background, but i have the problem that when I move it through different points, it shows a default background instead of showing the background of the "map". This messes the aspect of the game table.
I've tried this code in my program ,but it makes the ships default position is in the panel(which I do not want) and it doesn't solve the problem I described earlier (when you move ships over the others spaces)
Barco1.Parent = panel1;
Barco1.BackColor = Color.Transparent;
An example of one of the ships
As you can see in the picture, there are:
Form with a BackgroundImage,
Panel with BackColor = Color.Transparent and BackgroundImage = some-image and
PictureBox with BackColor = Color.Transparent and an image as its Image property.
It should work for you.
It looks like You are setting the Image background as Transparent but You are adding that Image into another Panel!
Barco1.Parent = panel1;
So, Set the Background Color of the Panel1 as Transparent:
panel1.BackgroundColor=Color.Transparent;

Make Form Transparent

I am trying to make a transparent form that will be shown on the bottom right corner of the screen. In that form, I have an image as a background that I am rotating. The issue is, when I use the following code to make the form transparent, I am getting outlines on the image that is equivalent to the color I set for the transparency key/background. Is this because of the image, or is there a way to fix this programmatically?
CODE:
this.TransparencyKey = Color.Orange;
this.BackColor = Color.Orange;
This gives me an orange outline around my image.
You can't make the border transparent but you can get rid of it altogether.
To get rid of the border you would use this.
FormBorderStyle = FormBorderStyle.None;

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

Categories

Resources