C# WinForms - Listview loading Images
I have loaded a collection of images into a folder(icons), and I am wondering how I can load all of these into a listview during the startup of the program. I am trying to get them to load into the view, showing the picture with a caption or description under the image.
After this, I plan(somehow) to select one and click within a picturebox to add the icon wit开发者_Python百科hin the box at the mouse cursor.
I am relatively new to doing these types of things within C#.
I think you need the ListView.LargeImageList or ListView.SmallImageList property.
Note that their default value is null, meaning that you have to assign a new ImageList object to them. After this you can load your images to the ImageList.
You can then set the index of the image to display with the ListViewItem.ImageIndex property.
As for loading images from files, you can use the Image.FromFile method.
I am not quite sure that I understand completely what you're trying to achieve from this point on, but I think the ListView.ItemSelectionChanged event can give you what you want.
ListView does not support embedded PictureBoxes or other controls, but you can use ImageList
as ShdNx noted.
Be sure to do loading on separate thread and synchronize properly (i.e. call BeginInvoke when updating the ImageList). This will ensure your UI won't hang during loading.
There is also 3rd party component Better Thumbnail Browser for exactly this (it supports automatic loading from a folder, database or other source, zooming, check boxes, multi-pass loading, image caching and many other goodies):
精彩评论