简体   繁体   中英

PictureBox transparency - not working properly

I have a PictureBox (map) on that I added other PictureBoxes(pins). (on winforms application). I set pin backcolor transparent. Every pin's parent is the map. The problem is that pins transparency not working properly. Every pin has the map background. There are more than 100 pins, and where there are more pins close, you can see the pin corners, if the map background is different of pin background. I tried also with panel and label instead of PictureBox, but without success. Please give me an idea how to solve the problem. Thank you.

Well, duh. Windows isn't Photoshop. Or Flash. Or Silverlight. Or WPF.

Windows uses a very simple layering system that allows for transparency under certain conditions, but it's really more of a workaround than a full-blown layered system. Basically, when you want to render an image transparently, you first ask the control under you to render itself, and then you render over that.

Due to the way the whole hierarchy works, this means that by default, transparency only works in a parent-child relationship - a child can easily render the parent as part of itself, and it can even omit rendering its own background under certain circumstances. So if you make your pins children of your background, transparency is going to work as expected.

However, PictureBox is only really designed for showing pictures anyway. If you need to render a map with hundreds of pins, you almost certainly don't want to use windows controls to do that. An owner-drawn control that handles rendering the background and the pins will probably work better. If that's too hard for your use case, you might want to have a look at WPF - you can easily embed a WPF control inside a Winforms control, and WPF gives you a lot better tools for what you're trying to do.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM