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 (822488)
The information in this article applies to:
- Microsoft Visual Basic .NET (2003)
- Microsoft Visual Basic .NET (2002)
- Microsoft Visual C# .NET (2003)
- Microsoft Visual C# .NET (2002)
SYMPTOMSWhen 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.WORKAROUNDTo 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 "Steps to Reproduce the Behavior"
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("c:\\Example.ico")
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("c:\\Example.ico");
e.Graphics.DrawIcon(Icon1,0,0);
} Note Replace c:\\Example.ico 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.
REFERENCESFor more information about the DrawIcon method, visit the following Microsoft Developer Network (MSDN)
Web site: For more information about the Paint event, visit the following MSDN Web site:
Modification Type: | Minor | Last Reviewed: | 2/3/2006 |
---|
Keywords: | kbvs2005doesnotapply kbvs2005swept kbvs2002sp1sweep kbWindowsForms kbControl kbdisplay kbIcon kbbug KB822488 kbAudDeveloper |
---|
|