views:

86

answers:

2

Hi all,

I'm using resources in VB.NET(2008) to manage my files and have 3 icon files that need to be on 3 buttons on my form (clicking the button changes the icon of the form tot the pressed button)

ICO_1.ico

ICO_2.ico

ICO_3.ico

but when I try the code below i get the error that "Value of type system.drawing.icon cannot be converted to system.drawing.image" any idea what's wrong?

btnIcon1.image = my.resources.ICO_1

btnIcon2.image = my.resources.ICO_2

+1  A: 

Exactly what it says, a button wants a bitmap, not an icon. You can use Icon.ToBitmap() but the resulting bitmap usually looks pretty bad. Use a good image editor to get a better result, Visual Studio has one. Add the resulting bitmap to your resources.

Hans Passant
A: 

To add to Hans' reply, I've found that using all .bmp files in My.Resources for the project works best, and just use a small function to convert the bitmap to an icon to use, for example, as the icon on a WinForm:

Public Shared Function ConvertBitmapToIcon(ByVal resourceBitmap As Bitmap) As Icon
    Return Icon.FromHandle(resourceBitmap.GetHicon())
End Function

The only time I need an actual .ico file is for the icon of the compiled .exe.

HardCode