在C#窗体中重叠透明的GIF错误 [英] Overlapping transparent gifs bug in C# windows forms

查看:92
本文介绍了在C#窗体中重叠透明的GIF错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用C#Windows窗体,我有以下问题:

我有一个程序在表单中有一个背景图片(不在图片框中),上面有2个图片框,有2个透明的Gif,它们重叠,但前面的gif打开一个洞,他的透明区域到下面的gif,在那个区域出现了窗体的背景图片,有没有办法显示那些2个GIF重叠而没有打开一个洞一个到另一个?或者它是C#的弱点?



谢谢



我尝试了什么:



我没有代码可以发布,因为我用拖放鼠标做了所有事情。

解决方案

< blockquote>你不会喜欢这个。这不是一个错误,至少不是在Windows窗体或控件中。



这是一个错误,你理解控件如何在Windows窗体中工作。



首先,控件不透明。但我听到你说我将PictureBox的背景设置为透明!是的,但透明并不意味着你认为它意味着什么。



将控件的背景设置为Transparent只是告诉控件采取背景属性控件所在的容器,即您的表单。因此,如果控件的背景与其容器的背景匹配,则透明给出了透明的错觉,但仅在某些条件下。



在其中一种情况下,当您的顶部(以Z顺序术语)PictureBox与较低级别的PictureBox重叠时,会破坏透明度的错觉。较低级别PictureBox占用的像素由较高级别的ImageBox透支。由于较高级别PictureBox的背景与Form的背景相匹配,因此它会给你的低级图片框消失或者有一个洞的错觉。



所以你怎么解决这个问题?这样做有各种各样的技巧。什么是适用的取决于你对你的图像做什么。



一种方法是根本不使用PictureBoxes。相反,您可以使用自己的绘图代码自己在Form表面上绘制图像。这有多复杂取决于您的应用程序。


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.

解决方案

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.


这篇关于在C#窗体中重叠透明的GIF错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆