c# - Adding an image to array elements -


i making card game have created 10 different cards, have implemented pictures program in resources area on right. card structure looks this:

 public form1()     {         cards = new playcard[10];         cards[0] = new playcard("harry", 97, 33, 40);         cards[1] = new playcard("dave", 80, 91, 41);         cards[2] = new playcard("randle", 90, 13, 45);         cards[3] = new playcard("zach", 30, 98, 81);         cards[4] = new playcard("shorty", 30, 89, 99);         cards[5] = new playcard("matt", 75, 81, 72);         cards[6] = new playcard("aaron", 89, 82, 80);         cards[7] = new playcard("ryan", 25, 83, 71);         cards[8] = new playcard("stephen", 96, 100, 100);         cards[9] = new playcard("david", 90, 37, 70);          initializecomponent();     } 

i'm wondering how corresponding picture show determined on card shown

thanks

use imagelist. can name each image correspond names. there introduction imagelists , how add images @ run-time , design-time here.

first add images (shown @ run-time):

imagelist1.images.add("pic1", image.fromfile("c:\\mypic.jpg")); 

to remove image collection:

imagelist1.images.removeat(listbox1.selectedindex); imagelist1.images..removebykey("pic1"); 

to access images, image image collection:

panel1.backgroundimage = imagelist1.images["david"]; 

or array:

panel1.backgroundimage = imagelist1.images[cards[i][0]]; 

i hope helps.


edit. address comments of above not being oop. instead of using imagelist add image playcard object. there option use dictionary<string, image> handle mapping, again construed non-oop.


Comments

Popular posts from this blog

php - mySql Join with 4 tables -

css - Text drops down with smaller window -

c# - DetailsView in ASP.Net - How to add another column on the side/add a control in each row? -