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 "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 CodePrivate 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.
MORE INFORMATION
Steps to Reproduce the Behavior
- Start Microsoft Visual Studio .NET 2002 or start Microsoft Visual Studio .NET 2003.
- On the File menu, point to New, and then click Project.
- Under Project Types, click Visual Basic Projects or click Visual C# Projects.
- Click Windows Application under Templates, and then click OK.
By default, Form1 is added to the project.
- On the View menu, click Toolbox.
- Add a Button control to Form1.
- Right-click Button1, and then click Properties.
- 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.
- On the File menu, click Save All to save the project.
- On the Debug menu, click Start to run the project.
Form1 appears on the screen. The icon on Button1 is not alpha-blended.
REFERENCES
For 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:
Keywords: kbvs2005doesnotapply kbvs2005swept kbvs2002sp1sweep kbwindowsforms kbcontrol kbdisplay kbicon kbbug KB822488