BUG: The TransparencyKey property is not effective for Windows forms if the color depth of the monitor is set to a value that is greater than 24-bit (822495)
The information in this article applies to:
- Microsoft Visual Basic 2005
- Microsoft Visual Basic .NET (2003)
- Microsoft Visual Basic .NET (2002)
- Microsoft Visual C# 2005, Express Edition
- Microsoft Visual C# .NET (2003)
- Microsoft Visual C# .NET (2002)
SYMPTOMSWhen you run a Microsoft Windows application with the TransparencyKey property of the form set to one of the colors of the background
image, areas of the form that match the color that you set the TransparencyKey property to are not rendered as transparent.CAUSEThis bug occurs when the color depth of the monitor is set
to a value that is greater than 24-bit. When the color depth of the monitor is
set to a value that is greater than 24-bit, the TransparencyKey property is not effective. Therefore, the areas on the form that
match the color you set the TransparencyKey property to are not rendered as transparent. WORKAROUNDTo work around this bug, programmatically set the BackgroundImage property and the TransparencyKey property. To do this, follow these steps:
- Create a sample bitmap file (.bmp) or select a bitmap file
that is already available on your computer.
- Append the following code in the Form1
class constructor after the InitializeComponent
statement.
Microsoft Visual Basic .NET or Microsoft Visual Basic 2005 Code
Dim Img As Bitmap = Bitmap.FromFile("c:\\Example.bmp")
'The color at Pixel(10,10) is rendered as transparent for the complete background.
Img.MakeTransparent(Img.GetPixel(10, 10))
Me.BackgroundImage = Img
Me.TransparencyKey = Img.GetPixel(10, 10) Microsoft Visual C# .NET or Microsoft Visual C# 2005 Code
System.Drawing.Bitmap Img = new System.Drawing.Bitmap("c:\\Example.bmp");
//The color at Pixel(10,10) is rendered as transparent for the complete background.
Img.MakeTransparent(Img.GetPixel(10,10));
this.BackgroundImage = Img;
this.TransparencyKey = Img.GetPixel(10,10);
- Rebuild the application.
Note In the sample code, modify
C:\\ Example.bmp based on the background image of
your computer. STATUS
Microsoft has confirmed that this is a bug in the Microsoft products that are
listed at the beginning of this article.
REFERENCESFor more information about the TransparencyKey property, visit the following Microsoft Web site:
Modification Type: | Minor | Last Reviewed: | 10/3/2006 |
---|
Keywords: | kbvs2005applies kbvs2005swept kbProperties kbColor kbBitmap kbdisplay kbWindowsForms kbbug KB822495 kbAudDeveloper |
---|
|