Using an icon resource as a button image

  • Thread starter Thread starter Steve McKewen
  • Start date Start date
S

Steve McKewen

I am using VS2005 in a cli managed application.

I have buttons which load icon files to use as button images.
I use icons so that the images are already transparent when placed. The IDE
converts these to images and stores them in the form resx file, and I change
them like this:
this->btnReplay->Image = Image::FromFile("ButtonDown.ico");

I want to keep the icons in a resource file and load them from there, but I
am having trouble converting the resource icons to images. This works OK

System::Drawing::Icon^ aDownIcon = (cli::safe_cast<System::Drawing::Icon^
(aResourceManager->GetObject("ButtonDown")));

But I can't cast the icon to an Image in order to assign it to the button's
image property.

Is there a simple way to do this?

Steve
 
Found it.

You have to use the ToBitmap method in the Icon object, then that will
convert to an Image.

Image^ aImage = theIcon->ToBitmap();

Steve
 
Back
Top