Using an icon resource as a button image

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
 
S

Steve McKewen

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
 

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