Пример #1
0
        public static void UpdateImageView(Dictionary <string, Bitmap> imageDict, ImageList imageList, ListView imageView, bool reflesh)
        {
            if (reflesh)
            {
                for (int i = 0; i < imageList.Images.Count; i++)
                {
                    imageList.Images[i].Dispose();
                }
                imageList.Images.Clear();
                imageView.Items.Clear();
            }
            foreach (var kv in imageDict)
            {
                string key = kv.Key;

                // キーが同じだったら上書き
                bool exist = false;
                for (int i = imageView.Items.Count - 1; i >= 0; i--)
                {
                    string key1 = imageView.Items[i].ImageKey;
                    if (key == key1)
                    {
                        exist = true;
                        if (reflesh)
                        {
                            imageList.Images[imageView.Items[i].ImageKey].Dispose();
                            imageList.Images.RemoveByKey(imageView.Items[i].ImageKey);
                            imageView.Items.RemoveAt(i);
                            exist = false;
                        }
                    }
                }

                if (!exist)
                {
                    imageList.Images.Add(kv.Key, BitmapHandler.CreateThumbnail(kv.Value, imageList.ImageSize.Width, imageList.ImageSize.Height));
                    imageView.Items.Add(key, kv.Key);
                }
            }
        }