Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Transparent background on winforms?

I wanted to make my windows form transparent so removed the borders, controls and everything leaving only the forms box, then I tried to the BackColor and TransparencyKey to transparent but it didnt work out as BackColor would not accept transparent color. After searching around I found this at msdn:

SetStyle(ControlStyles.UserPaint, true); SetStyle(ControlStyles.OptimizedDoubleBuffer, true); SetStyle(ControlStyles.SupportsTransparentBackColor, true); this.BackColor = Color.Transparent; this.TransparencyKey = BackColor; 

Unhappyly it did not work either. I still get the grey or any other selected color background.

All I wanted to do is to have the windows form transparent so I could use a background image that would act as if it was my windows form.

I searched around here and saw many topics in regards opacity which is not what I am looking for and also saw some in regards this method I was trying but have not found an answer yet.

Hope anyone can light my path.

UPDATE:

image removed as problem is solved

like image 214
Prix Avatar asked Dec 08 '10 12:12

Prix


People also ask

How do I change the background in Windows form?

Set the background in the Windows Forms DesignerSelect the Custom tab to display a palette of colors. Select the Web or System tab to display a list of predefined names for colors, and then select a color.

Is WinForms outdated?

Win Form has been used to develop many applications. Because of its high age (born in 2003), WinForm was officially declared dead by Microsoft in 2014.

How do I make a group box transparent in C#?

If you need to make a custom control that inherits form Control to support transparent background, you should add SetStyle(ControlStyles. SupportsTransparentBackColor, true); in constructor.


2 Answers

The manner I have used before is to use a wild color (a color no one in their right mind would use) for the BackColor and then set the transparency key to that.

this.BackColor = Color.LimeGreen; this.TransparencyKey = Color.LimeGreen; 
like image 160
Joel Etherton Avatar answered Oct 05 '22 21:10

Joel Etherton


A simple solution to get a transparent background in a windows form is to overwrite the OnPaintBackground method like this:

protected override void OnPaintBackground(PaintEventArgs e) {     //empty implementation } 

(Notice that the base.OnpaintBackground(e) is removed from the function)

like image 43
Alexander Cosman Avatar answered Oct 05 '22 20:10

Alexander Cosman