Click here to Skip to main content
15,946,527 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I use C# Windows Forms and i have the following problem:
I have a program with a background picture in the form (not in picturebox)and there are 2 picture boxes over it, with 2 transparent Gifs, and they overlapping, but the gif in front opens a hole with his transparent area to the gif below and in that area appearing the background picture of the form, is there a way the display those 2 gifs overlapping without open a hole the one to the other? or it's a weakness of C#?

Thanks

What I have tried:

I have no code to post because I did everything with the mouse drag and drop.
Posted
Updated 13-Mar-19 14:29pm

1 solution

You're not going to like this. It's not a bug, at least not in Windows Forms or the controls.

It's a bug in your understanding of how controls work in Windows Forms.

First, controls are not transparent. But I hear you saying "I set the background of the PictureBox to Transparent!" Yeah, but Transparent doesn't mean what you think it means.

Setting the background of a control to Transparent just tells the control to take on the Background properties of the container the control sits in, namely, your Form. So, Transparent gives the illusion of being transparent if the background of the control matches the background of it's container, but only under certain conditions.

In one of those conditions, the illusion of transparency is broken when your top (in Z-Order terms) PictureBox overlaps a lower level PictureBox. The pixels occupied by the lower level PictureBox are overdrawn by the higher level one. Since the background of the higher level PictureBox matches the background of the Form, it gives the illusion your lower level picturebox is disappearing, or has a hole in it.

So how do you get around this? There's a variety of tricks to doing this. What is applicable depends on what you're doing with your images.

One method is to not use PictureBoxes at all. Instead, you handle drawing the images on the surface of the Form yourself with your own drawing code. How complicated this gets depends on your application though.
 
Share this answer
 
Comments
tool__ 14-Mar-19 6:57am    
Thanks for your answer you saved me from lots of work for nothing, drawing the pictures in windows forms i dont think it's possible since the pictures are very complicated an they must made in a drawing program. Can you suggest me any programing language that i can work with multiple overlaping transparent pictures? to diplay them the way photoshop does for example...
Ralf Meier 14-Mar-19 7:53am    
You have to create your own customized PictureBox which has a 'real' transparency-behaviour.
CodeProject has severall examples which show how to make a Control real-transparent.
This could be a way for you ... but you must decide if you want to go this way ...
Dave Kreskowiak 14-Mar-19 9:20am    
"Complicated" has nothing to do with it if you're displaying them in a PictureBox. That means you've got a file you can load with a Bitmap object and paint the image on the surface of the form yourself using the normal Graphics methods.
tool__ 14-Mar-19 11:49am    
I was looking around in WPF for half hour and figured out how to display multiple overlapping transparent gifs easily and perfectly displayed... I am not sure with which application to go, WPF looks better, it also has that code window in the bottom which makes much more sense, you put the cursor on a line and automatically selects the object that it refers to on the design window...

But i don't know what problems will occur in the future with WPF, my goal is to make a stand alone .exe file for windows,

What is your opinion on WPF in general?
Dave Kreskowiak 14-Mar-19 12:14pm    
WPF is superior to Windows Forms, IMHO.

The problem with it is the really steep learning curve.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900