Transparency of picture box

后端 未结 3 1182
被撕碎了的回忆
被撕碎了的回忆 2020-12-04 04:08

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

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

3条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-12-04 04:24

    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.

    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.

    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
    

提交回复
热议问题