c# - Properties.Resources.Image not working with ImageList -


i working on game dice , when clicked, change color keep same number.

i using imagelists (as requirement) , using red , blue die. setup using bitmaps. i'm not sure how images versus bitmaps work, saw suggestion use bitmaps took it.

 private bitmap reddie1 = properties.resources.die1;     private bitmap bluedie1 = properties.resources.die1s;     private bitmap reddie2 = properties.resources.die2;     private bitmap bluedie2 = properties.resources.die2s;     private bitmap reddie3 = properties.resources.die3;     private bitmap bluedie3 = properties.resources.die3s;     private bitmap reddie4 = properties.resources.die4;     private bitmap bluedie4 = properties.resources.die4s;     private bitmap reddie5 = properties.resources.die5;     private bitmap bluedie5 = properties.resources.die5s;     private bitmap reddie6 = properties.resources.die6;     private bitmap bluedie6 = properties.resources.die6s; 

i setup imagelists (reddieimages, bluedieimages) want use adding variables them. using variable testimages see if reddie1 variable, , reddie1 added reddieimages equal. variable false in debug mode.

      private void form1_load(object sender, eventargs e)     {         dicelabels[0] = dicelabel1;         dicelabels[1] = dicelabel2;         dicelabels[2] = dicelabel3;         dicelabels[3] = dicelabel4;         dicelabels[4] = dicelabel5;          reddieimages.images.add(reddie1);         reddieimages.images.add(reddie2);         reddieimages.images.add(reddie3);         reddieimages.images.add(reddie4);         reddieimages.images.add(reddie5);         reddieimages.images.add(reddie6);         //reddieimages.imagesize = new size(dieimagesize, dieimagesize);          bluedieimages.images.add(bluedie1);         bluedieimages.images.add(bluedie2);         bluedieimages.images.add(bluedie3);         bluedieimages.images.add(bluedie4);         bluedieimages.images.add(bluedie5);         bluedieimages.images.add(bluedie6);         //bluedieimages.imagesize = new size(dieimagesize, dieimagesize);          bool testimages = reddie1 == reddieimages.images[0]; 

i using imagelists see of labels clicked change color of die contains each picture (6 pictures of dice, sides 1-6). dicelabelindex array of labels using store images. in containsimage trying check index of reddieimages contains red image can replace blue version of image. dicelabel click allows me change color of image using containsimage method.

       private int containsimage(int dicelabelsindex)     {         int itemindex = -1;         int count = reddieimages.images.count;          (int = 0; < reddieimages.images.count; i++)         {             if (dicelabels[dicelabelsindex].image == reddieimages.images[i])             {                 itemindex = i;                 break;             }         }          return itemindex;     }      private void dicelabel1_click(object sender, eventargs e)     {         int imageindex = containsimage(0);          if (dicelabel1.image == reddieimages.images[imageindex])         {             dicelabel1.image = bluedieimages.images[imageindex];         }         else         {             dicelabel1.image = reddieimages.images[imageindex];         }     } 

overall need in making sure images equal way can compared in containsimage way can switch images when user clicks on label. yet images not equal though both same variable.

thanks help

imagelist not store images modified copies of them. don't create copy of reference same thing!

look @ imagesize , colordepth variables! serious: after adding image imagelist new image new size , color depth created.

so reddie1 == reddieimages.images[0] indeed false.

instead can use string key images:

first store in bitmaps' tag property:

private bitmap reddie1 = properties.resources.die1; reddie1.tag = "reddie1"; 

next use when add images imagelist:

reddieimages.images.add(reddie1.tag.tostring(), reddie1); 

now can write test this:

bool testimages = reddie1.tag.tostring() == reddieimages.images.keys[0]; 

also note difference between reference , value parameters: if imagesize , colordepth same, still new copy created , comparison between 2 copies false. , if load two images variable same source, not equal..

in contrast true:

bitmap copy1 = reddie1;         // contains reference reddie1 bool test = copy1 == reddie1;   // true 

for completeness' sake: system makes exception rule strings allow more natural comparisons, not images.

btw: image superclass can several things, notably bitmap or icon ..


Comments

Popular posts from this blog

ios - RestKit 0.20 — CoreData: error: Failed to call designated initializer on NSManagedObject class (again) -

laravel - PDOException in Connector.php line 55: SQLSTATE[HY000] [1045] Access denied for user 'root'@'localhost' (using password: YES) -

java - Digest auth with Spring Security using javaconfig -