Does # Graphics.Clear (Color.Transparent) malfunction?

I draw graphics on the control panel several times, and every time I want to start a new job with a transparent background. Therefore, I use:

Graphics graph = control.CreateGraphics(); graph.Clear(Color.Transparent); 

However, the graphics area appears black, not transparent. Any ideas?

+5
source share
2 answers

I have found an alternative way to achieve what I need. I create a new transparent bitmap with control dimensions, draw my things on it, and then use it as a background image for the control:

  Bitmap bitmap = new Bitmap(control.Width, control.Height, System.Drawing.Imaging.PixelFormat.Format32bppArgb); bitmap.MakeTransparent(); Graphics graph = Graphics.FromImage(bitmap); // draw stuff here ... control.BackgroundImage = bitmap; graph.Dispose(); 

This works great.

+2
source

because the picture does not have a transparency layer. You can use the transfer bit card. try this.

  tmp_bmp = new Bitmap(picturebox1.Width, picturebox1.Height, System.Drawing.Imaging.PixelFormat.Format32bppArgb); Graphics Canvas = Graphics.FromImage(tmp_bmp); picturebox1.Image = tmp_Type; Type_Canvas.Clear(Color.Transparent); 
0
source

Source: https://habr.com/ru/post/1204132/


All Articles