Draw icon with the alpha channel enabled

Here’s how to draw an icon in a control utilizing the icon’s built-in alpha channel.

private void cmdEmail_Paint(object sender, 
  System.Windows.Forms.PaintEventArgs e)
{
  System.Drawing.Icon icon;
  icon = new Icon(
    GetType().Module.Assembly.GetManifestResourceStream(
      "ActiveSolution.Lernia.SFI.WinClient.Images.mail.ico"),
    16, 16); 
  e.Graphics.DrawIcon(icon,0,0);
}

The name of the icon resource is easily found using ildasm. Double-click on the “M A N I F E S T” node and look for the icon in the window that opens.

Leave a Reply

Your email address will not be published. Required fields are marked *

Time limit is exhausted. Please reload CAPTCHA.

This site uses Akismet to reduce spam. Learn how your comment data is processed.