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)

SYMPTOMS

When 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.

CAUSE

This 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.

WORKAROUND

To work around this bug, programmatically set the BackgroundImage property and the TransparencyKey property. To do this, follow these steps:
  1. Create a sample bitmap file (.bmp) or select a bitmap file that is already available on your computer.
  2. 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);
    
  3. 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.

MORE INFORMATION

Steps to Reproduce the Behavior

  1. Start Microsoft Visual Studio .NET or Microsoft Visual Studio 2005.
  2. On the File menu, point to New, and then click Project.
  3. Under Project Types, click Visual Basic Projects or click Visual C# Projects.

    Note In Visual Studio 2005, click Visual Basic or Visual C# under Project Types.
  4. Under Templates, click Windows Application, and then click OK.

    By default, Form1 is added to the project.
  5. Right-click Form1, and then click Properties.
  6. In the Properties window, set the BackgroundImage property to the background image that you use as the background for the form.
  7. Set the TransparencyKey property of Form1 to one of the colors of the background image.
  8. On the File menu, click Save All to save the project.
  9. On the Debug menu, click Start to run the application.

    By default, Form1 appears on the screen. The areas of the form that match the color you set the TransparencyKey property to are not rendered as transparent.

REFERENCES

For more information about the TransparencyKey property, visit the following Microsoft Web site:

Modification Type:MinorLast Reviewed:10/3/2006
Keywords:kbvs2005applies kbvs2005swept kbProperties kbColor kbBitmap kbdisplay kbWindowsForms kbbug KB822495 kbAudDeveloper