Get an image name or resource from button

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hello,

Maybe I have been staring too hard at this problem for too long. I would
like to have an if statement like the following:

if(RefreshButton.Image == global::myProject.Properties.Resources.Refresh)
{
// refresh the browser....
}

Although this is syntactically correct, it is always evaluating to false.

Isn't there some kind of name property I can grab from the button image? It
seems the button has everything you would ever want to know about the image
on it except the actual name or resource of the image. Even so, I am not
sure what the right part of the statement would look like either.

Is there a simple solution to this I am not seeing?

Thanks,

Rob K
 
Rob,

The reason this doesn't work is that == is performing a reference
equality check. When you use
global::myProject.Properties.Resources.Refresh, it is getting a stream from
the assembly, and creating a new Bitmap object. So every time you call
this, it is creating a new image.

You will have no choice but to perform a value equality check. However,
you have to write this yourself. It's not something that is easy, as you
would have to check the sizes, then check the bit depths of each of the
pixels, then scan through each of the pixels and see if the R, G, B, and A
values match.

In light of this, you might want to keep track of how you are setting
the image (set a flag somewhere), and then check the flag, which will give
you a value that is easier to discern.

Hope this helps.
 
Nicholas! Thank you so much for responding. Not the answer I was hoping
for, but a quick path to the solution.

Setting a flag sounds like the way to go, so I will do that.

Thank you so much for sharing your knowledge with me :~}

Rob K
 

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

Back
Top