VB中的图片框透明度 [英] Picture box transparency in vb
问题描述
运行代码时,即使我在属性窗口中将背景色设置为透明,图片框也具有背景色.有什么想法吗?
When i run my code, the picture box has a background colour, even though I have set the background colour to transparent in the properties window. any ideas?
推荐答案
我假设您正在将PictureBox
与其他控件重叠,并且希望可以看到PictureBox
.那不是它的工作原理-具有透明背景的控件仅相对于其父级是透明的,而不是其他控件.您可以通过覆盖表单的OnPaint
方法来使用GDI +绘制它们:
I assume you're overlapping a PictureBox
over some other control and expecting to see through the PictureBox
. That's not how it works - controls with transparent backgrounds are only transparent relative to their parent, not other controls. You could draw them using GDI+ by overriding the OnPaint
method of your form:
Private Shared ReadOnly SomeImage As Image = My.Resources.blah 'Get your image somewhere
Protected Overrides Sub OnPaint(ByVal e As PaintEventArgs)
Dim g As Graphics = e.Graphics
g.DrawImage(SomeImage, xCoordinate, yCoordinate)
'Draw as many images or text as you want.
End Sub
此外,似乎人们大多在寻找此功能来制作游戏.你在做游戏吗?在这种情况下,请在制作游戏之前学习图形.有很多很好的教程.
Also, it seems that people are mostly looking for this functionality to make a game. Are you making a game? Please learn graphics before making a game if this is the case. There are many good tutorials out there.
这篇关于VB中的图片框透明度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!