-
Jan 18th, 2015, 05:26 PM
#1
Thread Starter
Junior Member
How to make pictures transparent on Visual Basic?
I am trying to put transparent PNG images on my forms but they seem to be showing white spaces. I also went to the properties window to set each image to transparent but no success. How can I approach this issue?
-
Jan 18th, 2015, 07:14 PM
#2
Re: How to make pictures transparent on Visual Basic?
Forms controls only do transparency by showing you the Backcolor (and BackgroundImage) of the Parent control. So if you put a PictureBox on a Form, set its BackColor to Transparent and its Image to a transparent PNG, you will see the Form's background in the transparent areas. It sounds like you want something else to show. Could you please give more detail: what do you want to show in the transparent areas?
BB
-
Jan 18th, 2015, 07:33 PM
#3
Thread Starter
Junior Member
Re: How to make pictures transparent on Visual Basic?
Originally Posted by boops boops
Forms controls only do transparency by showing you the Backcolor (and BackgroundImage) of the Parent control. So if you put a PictureBox on a Form, set its BackColor to Transparent and its Image to a transparent PNG, you will see the Form's background in the transparent areas. It sounds like you want something else to show. Could you please give more detail: what do you want to show in the transparent areas?
BB
I am trying to put my pictures in buttons actually but they show the whitespaces in the buttons
-
Jan 18th, 2015, 07:47 PM
#4
Re: How to make pictures transparent on Visual Basic?
I have no problem showing a transparent PNG on a Button by setting the button's Image property. Maybe the "transparent" areas of your PNGs aren't really transparent after all. Did you save it as a 32-bit image?
If the background is actually white, you could make all the white pixels transparent like this:
Code:
Dim bmp As New Bitmap(filename)
bmp.MakeTransparent(Color.White)
Button1.Image=bmp
MakeTransparent will only work for the exact specified color (White must be [255, 255, 255] and not [254, 255, 255]).
-
Mar 5th, 2022, 04:40 AM
#5
Re: How to make pictures transparent on Visual Basic?
Originally Posted by boops boops
Forms controls only do transparency by showing you the Backcolor (and BackgroundImage) of the Parent control. So if you put a PictureBox on a Form, set its BackColor to Transparent and its Image to a transparent PNG, you will see the Form's background in the transparent areas.
BB
Hi BB,
I see this was 2015, but how is it done in VS2019 (I've stopped using VS2022 until they fix the resources issue)
In my VS2019, there is no option for PictureBox BackColor transparent
Poppa
PS
I meant to mention...
Code:
PictureBox1.BackColor = Color.Transparent
...doesn't throw any errors, but neither does it work.
Pop
Last edited by Poppa Mintin; Mar 5th, 2022 at 05:11 AM.
Reason: Added PS
Along with the sunshine there has to be a little rain sometime.
-
Mar 5th, 2022, 10:45 AM
#6
Re: How to make pictures transparent on Visual Basic?
I can't reproduce your problem. I tried .NET Framework 4.8 (VS2019) and 3.5 ClientFramework as well as .NET 6.0 (VS2022). A picture box with a partly transparent BackColor and with a partly transparent Image provided a satisfactory see-through experience in all cases.
BB
-
Mar 5th, 2022, 11:35 AM
#7
Re: How to make pictures transparent on Visual Basic?
I'm using : -
Microsoft Visual Studio Community 2019
Version 16.11.8
Microsoft .NET Framework
Version 4.8.04084
I've just checked that the .png file DOES have transparent areas (In fact most of it is transparent).
The PictureBox margins are all 0, SizeMode is Stretchimage, it's only 50,50px, when the form opens it's BackColor is the same as that of the form.
It won't accept BackColor = Transparent. Huh! I just tried that again to get the exact error message and it accepted it ! (maybe I misspelt it previously)
However, running the code there is still no transparency.
I've tried:-
Code:
Dim tran As Color = My.Resources.ManRed.GetPixel(1, 1)
Man.TransparencyKey = tran
' And
ManRed.MakeTransparent(backColor)
Even...
Code:
Me.TransparencyKey = tran
...doesn't work, that reduces a lot of the Form details (Also a bitmap) tranparent, but Not the flamin' Picturebox's .
'Man' is the name of the PictureBox.
Poppa
Along with the sunshine there has to be a little rain sometime.
-
Mar 5th, 2022, 02:57 PM
#8
Re: How to make pictures transparent on Visual Basic?
I suppose you are aware that both TransparencyKey and Bitmap.MakeTransparent respond only to an exact A, R, G and B combination. If one of these bytes deviates by 1 or more in 256, the rest will remain opaque.
That aside, I suggest you start from scratch using only the Designer in your preferred VS/Framework. This is just to help find the cause of your problem. Take a Form and give it a small, tiled background image. Then throw on a PictureBox and set its BackColor to something translucent. Finally, put a partly-transparent Image in the PictureBox.
Here's an example I made this way in the Designer. The dancing mice are the Form's BackgroundImage (default = Tile), the yellow area is the pb BackColor (ARGB values typed to the right of the property), and the ghost is the pb Image.
Does that work for you?
BB
Last edited by boops boops; Mar 5th, 2022 at 03:26 PM.
-
Mar 8th, 2022, 08:57 AM
#9
Re: How to make pictures transparent on Visual Basic?
Just got back to looking at this...
Took a fresh look and found that I was expecting transparent to work with an image in a picturebox instead of a background image... It's been working all along. !
I do however still have to type-in 'Transparent', it's still not in the selection menu.
Poppa
Along with the sunshine there has to be a little rain sometime.
-
Mar 8th, 2022, 12:52 PM
#10
Re: How to make pictures transparent on Visual Basic?
Never mind, at least the latest frameworks aren't bamboozling you. BB
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
|