# [.net] Displaying All Images In A Folder + C#

This topic is 4223 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

How would I go about displaying all the images in a folder in my windows form application?

##### Share on other sites
Just go through each file in the folder and load it into a pictureBox.

DirectoryInfo di = new DirectoryInfo(path);FileInfo[] files = di.GetFiles("*.*");foreach (FileInfo file in files){	pictureBox1.Image = Bitmap.FromFile(file.FullName);}

##### Share on other sites
Quote:
 Original post by HeadkazeJust go through each file in the folder and load it into a pictureBox.DirectoryInfo di = new DirectoryInfo(path);FileInfo[] files = di.GetFiles("*.*");foreach (FileInfo file in files){ pictureBox1.Image = Bitmap.FromFile(file.FullName);}

don't even need the "*.*" file specifier, just call GetFiles();

##### Share on other sites
Thats perfect, but what I am trying to do is well. Display all the images as a graphic (combining them all), making this graphic the image of a picturebox, then having a onmousedown command which depending on the image selected, will change the image on the map. Basically its a continuation of my map editor program I've asked questions for before. So now that I have the code to display the images, I need to think of a way to give each image its own id value. Or somehow figure out how say I select the image located at 1,2 and there are 4 images per row, then the image I selected would be the 5th image in the folder, and it would select the 5th image and display it for me.
Get my drift?

##### Share on other sites
That's a whole separate question.

You're saying that you want to have a big map view, and be able to click on one of the "tiles" and have it dig down to the higher res image?

If it were me, I would derive a new control from the PictureBox, which allows for the adding/compositing of images, and resolves mouseclicks into image selection.

##### Share on other sites
Kinda but not really. I've already gotten a system in place that displays my set of tiles (the map) in a picturebox. And an event that when I click on a specific tile in that picture box it will fill in a group of text boxes with the relevant data for that tile. What I want to do now, is have a seperate picturebox full of all the tiles available for that map (the tiles are separated into their component locations, example all the tiles which can be used for world maps are in a world folder). And when I click on a tile in the new picturebox, it will replace the tile already selected from the map. Basically I need to figure out how to give the tiles in the picturebox (the 2nd one with the images from the folder), a unique ID so that when I click on the image, it can figure out which tile exactly was clicked. I think I could potentially do it with a 2 dimensional array. Probably would be the easiest.

##### Share on other sites
Who is filling these new programmers' heads with ideas of using PictureBoxes for everything? Just draw everything to the form directly.

##### Share on other sites
Sounds like you would like to make a sorta sprite sheet of all your sprites, then when you click it, it would choose which tile you clicked and give you the relevent information. Well, actually, I would personally put all my tiles into 1 texture/bitmap anyways and then just show that.

That link is to SpriteSheetTool, it will let you choose which tiles to add, make a bounding box for ya if ya want, then export out 1 bitmap of all your tiles and a file describing font name, bounding box (if you chose to use it), tile location in the bitmap, etc.

If you use that program, you can just load up the bitmap. Then the text file and use the data from it to find out which tile was clicked.

1. 1
2. 2
3. 3
Rutin
20
4. 4
khawk
14
5. 5

• 9
• 11
• 11
• 23
• 12
• ### Forum Statistics

• Total Topics
633655
• Total Posts
3013187
×