Microsoft KB Archive/820640

= BUG: TransparencyKey does not work for double-buffered controls in 32-bit color mode =

Article ID: 820640

Article Last Modified on 11/26/2007

-

APPLIES TO


 * Microsoft Visual Basic 2005
 * Microsoft Visual Basic .NET 2003 Standard Edition
 * Microsoft Visual Basic .NET 2002 Standard Edition
 * Microsoft Visual C# 2005 Express Edition
 * Microsoft Visual C# .NET 2003 Standard Edition
 * Microsoft Visual C# .NET 2002 Standard Edition

-





SYMPTOMS
You may have a Microsoft Windows Form with a user control that has the DoubleBuffer control style bit set to TRUE. Or, you may have a Microsoft Windows Forms control (such as a Button, a PictureBox, a CheckBox, or a Label) with the DoubleBuffer property that is automatically set. When you set the TransparencyKey property of the Windows Form to the value of the BackColor property, and then run the application, the Form appears transparent and the control appears in color.

Note The color is set in the BackColor property of the Windows Form.

Note You must have the display Color quality set to 32-bit color mode.



RESOLUTION
To resolve this problem in a Microsoft Windows application with a Windows Forms control, follow these steps:
 * 1) Right-click Label1, and then click Properties.
 * 2) In the Properties window, set the FlatStyle property to System.
 * 3) On the Debug menu, click Start.

You may notice that both the Form and the Windows Forms control are transparent. This problem is mentioned in the &quot;More Information&quot; section of this article.

To resolve the problem in a Windows application with a user control, follow these steps:  In Solution Explorer, right-click UserControl1.vb and then click View Code.  Replace the existing SetStyle(ControlStyles.DoubleBuffer,               true) statement with the following statement:

Visual Basic .NET or Visual Basic 2005 Code SetStyle(ControlStyles.DoubleBuffer, False) Visual C# .NET or Visual C# 2005 Code SetStyle(ControlStyles.DoubleBuffer,false);  On the Debug menu, click Start.

You may notice that both the Form and the user control are transparent. This problem is mentioned in the &quot;More Information&quot; section of this article.



STATUS
Microsoft has confirmed that this is a problem in the Microsoft products that are listed in the &quot;Applies to&quot; section.



MORE INFORMATION
Note Before you start the &quot;Steps to Reproduce the Problem&quot;, follow these steps:
 * 1) Right-click Desktop, and then click Properties.
 * 2) Click the Settings tab.

Make sure that Color quality is set to Highest (32 bit). Some computers may not support 32-bit color quality because the color quality depends on the computer video card.

=== Steps to Reproduce the Problem

===

Windows Form with Windows Forms Control

 * 1) In Microsoft Visual Studio .NET or in Microsoft Visual Studio 2005, create a new Windows application by using either Visual Basic .NET, Visual Basic 2005, Visual C# 2005, or Visual C# .NET.

By default, Form1 is created.
 * 1) From the Toolbox, drag a Label control to Form1.
 * 2) Right-click Form1, and then click Properties.
 * 3) In the Properties window, select the BackColor property, and then click the Custom tab.

Select any color other than white.
 * 1) In the Properties window, set the TransparencyKey property to the same value as the BackColor property.
 * 2) On the Debug menu, click Start.

You may see that the form is transparent. However, the label appears in the color that is set in the BackColor property.

=== Steps to Reproduce the Problem

===

Windows Form with a User Control
 In Visual Studio .NET or ijn Visual Studio 2005, create a new Windows Control Library by using either Visual Basic .NET, Visual Basic 2005, Visual C# 2005, or Visual C# .NET.

By default, UserControl1 is created.  On the View menu, click Code. In the Windows Form Designer generated code region, add the following statements in the constructor of UserControl1 after the InitializeComponent statement:

Visual Basic .NET or Visual Basic 2005 Code 'These Control Style bits enable double-buffering. SetStyle(ControlStyles.UserPaint,True) SetStyle(ControlStyles.AllPaintingInWmPaint, True) SetStyle(ControlStyles.DoubleBuffer, True) Visual C# .NET or Visual C# 2005 Code //These Control Style bits enable double-buffering. SetStyle(ControlStyles.UserPaint,true); SetStyle(ControlStyles.AllPaintingInWmPaint, true); SetStyle(ControlStyles.DoubleBuffer, true); </li> On the Build menu, click Build Solution.</li> On the File menu, point to Add Project, and then click New Project. Under the Project Types section, select Visual Basic Projects. Under the Templates section, select Windows Application.

Note In Visual Studio 2005, click Visual Basic under Project Types.

By default, Form1 is created.</li> From the Toolbox, drag a UserControl1 control to Form1.</li> Right-click Form1, and then click Properties.</li> In the Properties window, select the BackColor property, and then click the Custom tab. Select any color other than white.</li> In the Properties window, set the TransparencyKey property to the same value as the BackColor property.</li> In Solution Explorer, right-click WindowsApplication1, and then click Set as StartUp Project.</li> On the Debug menu, click Start.

You may see that the form is transparent. However, the user control appears in the color that is set in the BackColor property.</li></ol>

<div class="references_section">