Picture box transparency in vb

≡放荡痞女 提交于 2019-12-08 03:26:00

问题


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?


回答1:


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.



来源:https://stackoverflow.com/questions/9342274/picture-box-transparency-in-vb

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!