图片框的透明度 [英] Transparency of picture box

查看:27
本文介绍了图片框的透明度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我只是在我的简单问题中寻找答案.在这里

Im just looking for an answer in my simple problem. Here it is

我有一个带有透明 background 图像的图片框 我将图片框 backcolor 设置为透明.

I have a pricturebox that has image with transparent background i Set the picturebox backcoloras transparent.

之后,图片有透明的bg.但是在我添加了这段代码之后

and after that, the picture has transparent bg. But after i added this code

ìmg1.Left = windows.forms.cursor.Position.X - me.Leftìmg1.Top= windows.forms.cursor.Position.Y - me.Top

'使用img作为光标的代码

图像背景不是这样透明的

the image bg is not really transparent like this

我认为透明的backcolor并不是真正透明的.它只会获取表单的 backcolor 并将其用作图像的 backcolor 而不是透明.

I think the transaparent backcoloris not really transparent. it will only get the backcolorof form and use it as backcolorof image instead of transparent.

有没有办法让它完全透明?

Is there any solution to make it fully transparent?

推荐答案

你的假设是正确的.
winforms 中的透明度并不意味着对象实际上是透明的.相反,这意味着它将显示其父对象而不是背景,包括背景、图像和文本,但不包括其上的任何其他控件,因此您的问题.
由于您最上面的图片框的父控件不是也不能是其他图片框,因此您最上面的图片框具有透明背景这一事实将无济于事.

You are correct in your assumption.
Transparency in winforms does not mean that the object is actually transparent. Instead, it means that it will display it's parent object instead of it's background, including it's background, images and text, but not including any other controls on it, hence your problem.
Since the parent control of your top most picture box is not and can not be the other picture boxes, the fact that your top most picture box have a transparent background will not help.

不幸的是,使用表单的 TransparencyKey 属性也无济于事.(它会使所选颜色透明,但会产生意外(通常是不希望的)结果.

Unfortunately, using the form's TransparencyKey property will also not help for this. (It will make the selected color transparent, but will yield unexpected (and usually undesired) results.

为了实现您的目标,您必须遵循 OneFineDay 在评论中的建议,并使用 Graphics 自己绘制图像.
幸运的是,这很容易做到:

In order to achieve your goal, you will have to follow OneFineDay's advice in the comments, and use Graphics to draw the image yourself.
Fortunately, this is very easy to do:

Public Sub DrawImage(Image as Image, Location As Point)
    Using(Dim g as Graphics = Me.CreateGraphics())
        g.DrawImage(Image, Location)
    EndUsing
End Sub

这篇关于图片框的透明度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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