|
-
Apr 6th, 2023, 11:02 PM
#1
Thread Starter
Addicted Member
Why isn’t my PictureBox background transparent?
I have a VB.net forms application. The majority of the form is a DataGridView with the cells having a variety of background colors. In the application, when a button is clicked, a PictureBox is created and it is filled with a PNG image. The image is a circle – black outline with a white interior and a transparent background.
Following is the code used to place the picture box:
Code:
Dim xpos As Integer = <some number>
Dim yPos As Integer = <some number>
Dim pba as PictureBox = New PictureBox
pba.BackColor = Color.Transparent
pba.Height = 70
pba.Width = 70
pba.Location = New Point(xPos, yPos)
pba.Image = My.Resources.circle
Controls.Add(pba)
pba.BringToFront()
All of this works fine, but the area outside the circle and inside the PictureBox is white, not transparent. I have searched, but have found nothing to address this issue. Did I miss something obvious? Please help.
-
Apr 6th, 2023, 11:19 PM
#2
Re: Why isn’t my PictureBox background transparent?
There is no real transparency in Windows Forms. When you make a control transparent, what actually happens is that the control copies the area of its parent that it is covering and paints that in its background. Because your form is the parent of the PictureBox, what you're seeing is the form painted in its background. You may have to use GDI+ to draw the image over the DataGridView instead, although that may be complex because you may have to draw in each cell individually. I'm not sure that you can just draw over the top of the grid as a whole.
-
Apr 7th, 2023, 12:12 AM
#3
Re: Why isn’t my PictureBox background transparent?
 Originally Posted by jmcilhinney
...I'm not sure that you can just draw over the top of the grid as a whole.
You can draw over the dgv. Just handle the Paint event, and use e.Graphics
- Coding Examples:
- Features:
- Online Games:
- Compiled Games:
-
Apr 7th, 2023, 02:07 AM
#4
Re: Why isn’t my PictureBox background transparent?
 Originally Posted by .paul.
You can draw over the dgv. Just handle the Paint event, and use e.Graphics
Just tested and can confirm. The one exception is when editing a cell, the editing control will be displayed over the grid and so will obscure the drawing. If that's an issue, you'd have to handle the Paint event of the editing control too, although I'm not sure that a TextBox supports drawing over it anyway.
-
Apr 7th, 2023, 03:04 AM
#5
Re: Why isn’t my PictureBox background transparent?
I made a game in the past with transparent token in picturebox who move over an other picturebox. I used PNG files who allow transparency background
here is my test project for the movement if it can help : (project is to large for the local upload so here is a link )
https://www.swisstransfer.com/d/b280...1-2c490c425219
The best friend of any programmer is a search engine 
"Don't wish it was easier, wish you were better. Don't wish for less problems, wish for more skills. Don't wish for less challenges, wish for more wisdom" (J. Rohn)
“They did not know it was impossible so they did it” (Mark Twain)
-
Apr 7th, 2023, 04:21 AM
#6
Re: Why isn’t my PictureBox background transparent?
I’ve written a few games that use a dgv with graphics drawn on it.
Have a look at my compiled games, and guess which ones use a dgv…
- Coding Examples:
- Features:
- Online Games:
- Compiled Games:
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|