docs-desktop
docs-desktop copied to clipboard
Images in controls
The instructions on this page are a little too brief. It mentions nothing about the image having to have transparency or an alpha channel. Even with that information, it's hit or miss for BMP images and probably other formats; however, it works for a PNG. Load a PNG image containing transparent areas into a PictureBox, set the PictureBox.BackColor = Color.Transparent and the transparency shows through the image to what's underneath.
Hard to believe we still have to struggle with transparency these days.
Document Details
⚠ Do not edit this section. It is required for learn.microsoft.com ➟ GitHub issue linking.
- ID: dfb9d1a6-d910-39ea-dd9c-ca44fb47a91c
- Version Independent ID: 9f6948a4-9abc-2d40-cd1d-d28ca2df18e8
- Content: How to: Give Your Control a Transparent Background - Windows Forms .NET Framework
- Content Source: dotnet-desktop-guide/framework/winforms/controls/how-to-give-your-control-a-transparent-background.md
- Product: dotnet-framework
- Technology: dotnet-winforms
- GitHub Login: @adegeo
- Microsoft Alias: adegeo
Hi @EFEaglehouse yeah the article is definitely more generic as it's talking about the "background" property and not specifically transparent hosted content such as images or icons. I think it would be a good idea to add information about the picturebox control since that's a common scenario. However, we're not really going back through and updating .NET Framework articles as we're more focused on porting them to .NET 6/7/8. As part of porting this content (when it happens) we would improve the article.
I'll leave this issue open to track it during porting.
Also note, it's very common for a BMP to only have 24-bit pixel data, which doesn't include an alpha channel for transparency.