Microsoft KB Archive/822488

= BUG: The icon that is displayed on the control loses the alpha channel when you set the Image property of a Microsoft Windows Form control to a 32-bit alpha-blended icon =

Article ID: 822488

Article Last Modified on 5/16/2007

-

APPLIES TO


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

-





SYMPTOMS
When you set the Image property of a Microsoft Windows Form (Winform) control to a 32-bit alpha-blended icon, the icon that is displayed on the control loses the alpha channel. The transparent regions of the icon are rendered as solid. This behavior occurs at design time and at run time for the Winform control.



WORKAROUND
To work around this bug, override the Paint event handler for the Winform control, and then call the DrawIcon method. To do this, follow these steps.

Note These steps are based on the &quot;Steps to Reproduce the Behavior&quot; section of this article.  Right-click Form1, and then click View Code.  Append the following code to the Form1 class:

Microsoft Visual Basic .NET Code Private Sub Button1_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles Button1.Paint Dim icon1 As System.Drawing.Icon icon1 = New System.Drawing.Icon(&quot;c:\\Example.ico&quot;) e.Graphics.DrawIcon(icon1, 0, 0) End Sub Microsoft Visual C# .NET Code private void button1_Paint(object sender, System.Windows.Forms.PaintEventArgs e) { System.Drawing.Icon Icon1; Icon1 = new System.Drawing.Icon(&quot;c:\\Example.ico&quot;); e.Graphics.DrawIcon(Icon1,0,0); } Note Replace   with the path for your 32-bit alpha-blended icon.   Add the following event handler declaration to the InitializeComponent method of the Form1 class: this.button1.Paint += new System.Windows.Forms.PaintEventHandler(this.button1_Paint); 



STATUS
Microsoft has confirmed that this is a bug in the Microsoft products that are listed at the beginning of this article.



Steps to Reproduce the Behavior

 * 1) Start Microsoft Visual Studio .NET 2002 or start Microsoft Visual Studio .NET 2003.
 * 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.
 * 4) Click Windows Application under Templates, and then click OK.

By default, Form1 is added to the project.
 * 1) On the View menu, click Toolbox.
 * 2) Add a Button control to Form1.
 * 3) Right-click Button1, and then click Properties.
 * 4) In the Properties window, set the Image property to the 32-bit alpha-blended icon.

The icon is added to the Button control, but the alpha channel is lost.
 * 1) On the File menu, click Save All to save the project.
 * 2) On the Debug menu, click Start to run the project.

Form1 appears on the screen. The icon on Button1 is not alpha-blended.

