private Hashtable ImgMap = new Hashtable();
/// <summary>
/// 把指定文件夹下的图片加载放到imageList下并对应加入Hashtable
/// </summary>
private void InitImageList()
{
this.imageList1.Images.Clear();
this.imageList1.ImageSize = new Size(180, 90);
this.imageList1.ColorDepth = ColorDepth.Depth32Bit;
string filePath = AppDomain.CurrentDomain.BaseDirectory.ToString() + @"ResultViewTemp\ImageList";
var files = Directory.GetFiles(filePath, "*.*", SearchOption.AllDirectories).Where(s => s.EndsWith(".png") || s.EndsWith(".jpg"));
foreach (string imagefile in files)
{
string fileName = System.IO.Path.GetFileNameWithoutExtension(imagefile);
Image image = Image.FromFile(imagefile);
imageList1.Images.Add(image);
ImgMap.Add(fileName, image);
}
} |