Alpha-Blended Icons on Toolbar Buttons

A

Al

Hi All,

I am trying to get a 24x24 "Windows XP" icon to display correctly on a
button in my toolbar. My icon has 8 layers (16x16, 16x16, 24x24, 24x24,
32x32, 32x32, 48x48, 48x48) with each size having a 256 and windows xp
colored image. When my application runs, the icon with 256 colors appears
rather than the xp icon. I have tried using a manifest as well as
Application.EnableVisualStyles. No luck.

I have seen numerous articles about this problem but only a few solutions,
none of which I could not get to work. I would be very grateful if anybody
could point me to an actual solution.

Thanks,

Al
 
M

Mick Doherty

You need to add the Icons to the ImageList at runtime. At designtime the
ImageList Flattens the Alpha.

So as not to have to distribute the Icons seperately you can add them as
Embedded Resources.
Example follows:

Assumes Toolbar(ToolBar1) with 2 buttons on Form1, 2 Icons(icon1.ico,
icon2.ico) set as Embedded Resource and ImageList1.ColorDepth = Depth32Bit
\\\
Public Class Form1
Inherits Form

Shared Sub Main()
Application.EnableVisualStyles()
Application.DoEvents()
Application.Run(New Form1)
End Sub

#Region " Windows Form Designer Generated Code "
'Code not shown
#End Region

Private Sub Form_Load(...)...
Dim AlphaIcon1 as New Icon(GetType(Form1), "icon1.ico")
Dim AlphaIcon2 as New Icon(GetType(Form1), "icon2.ico")
Imagelist1.Images.Add(AlphaIcon1)
Imagelist1.Images.Add(AlphaIcon2)
Toolbar1.Buttons(0).ImageIndex=0
Toolbar1.Buttons(1).ImageIndex=1
End Sub
///

Note that the Iconnames are cAse sEnsitive. i.e. "icon1.ico" <> "icon1.ICO"
 
A

Al

Thanks Mick. That worked perfectly. I am surprised someone has to take the
time to program something like this.

Al


"Mick Doherty"
 
M

Mick Doherty

GTH.

As Workarounds go, this is one of the simple ones, although if you don't
know about it, it could turn out to be an impossible task.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top