Wednesday 15 May 2013

c# - Sorting an image list loaded from resources by name -



c# - Sorting an image list loaded from resources by name -

say have list<image>, add together images found in solution's resources using this;

using (resourceset resourceset = someproject.properties.resources.resourcemanager.getresourceset(cultureinfo.currentuiculture, true, true)) { foreach (dictionaryentry entry in resourceset) { somelist.add((image)entry.value); } }

in case, there'll 3 images in our resources. apple.png banana.png, cactus.png

how can sort list alphabetically can loop through in right order, getting apple -> banana -> cactus?

i've read how sort resourceset in c# tried apply situation no avail.

by myself i've tried assigning entry.key image's tag , doing somelist.orderby(f => f.tag).tolist();

here's total code utilize test this

list<image> somelist = new list<image>(); private void button1_click(object sender, eventargs e) { using (resourceset resourceset = windowsformsapplication52.properties.resources.resourcemanager.getresourceset(cultureinfo.currentuiculture, true, true)) { foreach (dictionaryentry entry in resourceset) { image = (image)entry.value; i.tag = entry.key; somelist.add((image)i); } somelist.orderby(f => f.tag).tolist(); } foreach(var x in somelist) { picturebox pb = new picturebox(); pb.image = x; pb.size = new system.drawing.size(200, 200); pb.sizemode = pictureboxsizemode.zoom; flowlayoutpanel1.controls.add(pb); } }

this result seem every time,

i don't know if takes file size business relationship in case file sizes of images in order. (apple.png largest, cactus smallest).

help appreciated.

you can add together images sorted dictionary image name key. foreach on dictionary retrieve images in alphabetical order name.

c# sorting visual-studio-2013

No comments:

Post a Comment