PDA

Click to See Complete Forum and Search --> : [RESOLVED] there must be another way (ToolStripDropDownButton)


Bongo
Nov 13th, 2006, 03:48 AM
Hi

I have a


StatusStrip with a ToolStripDropDownButton
ToolStripDownButton Property is set to "Image and Text"
Resourcefile with to pictures (Pic1 and Pic2)


assign during designmode a Image from the resource file called Pic1 to the property Image

during the run this Image has to be changed so i did



if (dropdownbutton.Image.Equals(Resources.Pic1))
{
dropdownbutton.Image = Resources.Pic2;
}
else
{
dropdownbutton.Image = Resources.Pic1;
}



does not work.

i am using now this methode
the Tag Property of the ToolStripDropDownButton becomes during design time the value "0"



if (dropdownbutton.Tag.Equals("1"))
{
dropdownbutton.Tag = "2";
dropdownbutton.Image = Resources.Pic2;
}
else
{
dropdownbutton.Tag = "1";
dropdownbutton.Image = Resources.Pic1;
}



There must be a better way ???

thx

Fromethius
Nov 13th, 2006, 05:32 AM
It is working right now? You just want it better? Better how? Shorter? No IF?

Bongo
Nov 13th, 2006, 06:05 AM
no i thing if an object has the methode equal (which i thing is to compare) there should be a way to say Image.Equal(image) should work. It works with other objects.

So i believe if did a workaround but i did not solve the real issue.

Bongo
Nov 13th, 2006, 07:45 AM
Or lets rephrase

WHY does
if(TooStripDropDownButton.Image.Equal(Resources.Image))
not work???

jmcilhinney
Nov 13th, 2006, 03:33 PM
Or lets rephrase

WHY does
if(TooStripDropDownButton.Image.Equal(Resources.Image))
not work???Because each time you get that property from your resources you get a new Image object. If you get the property twice then your creating two distinct Image objects so they are not equal. You should only be getting each resource once each. Assign them to variables and compare to those variables.

Bongo
Nov 14th, 2006, 01:18 AM
Because each time you get that property from your resources you get a new Image object. If you get the property twice then your creating two distinct Image objects so they are not equal. You should only be getting each resource once each. Assign them to variables and compare to those variables.

Hi jmcilhinney,

so if i would write

Image img1 = TooStripDropDownButton.Image;
Image img2 = Resources.Pic1;

if (img1.Equal(img2))

it should work. (cant try it in the moment - not an a developing comp)

If it works it would look better then the thingi with the tag.

thx

Bongo
Nov 14th, 2006, 05:56 AM
Image img1 = TooStripDropDownButton.Image;
Image img2 = Resources.Pic1;

if (img1.Equal(img2))



Tryed it - did not work :confused:

jmcilhinney
Nov 14th, 2006, 03:50 PM
Declare two class-level Image variables. Get your resource images once only and assign them to those variables. Now you ONLY set the Image property of your button from those variables and you ONLY compare the Image property of your button to those variables. Also, just use the '==' operator to compare two reference type objects.

Bongo
Nov 15th, 2006, 01:42 AM
@jmcilhinney

many thx