C# 動態 調整ImageList圖片大小

C# 動態 調整ImageList圖片大小

C# 動態 調整ImageList圖片大小


資料來源: https://stackoverflow.com/questions/43301283/how-to-change-existing-imagelist-image-size-of-listview


        public static void ResizeImageList(ImageList imageList, int newSize)//調整ImageList圖片大小
        {
            //https://stackoverflow.com/questions/43301283/how-to-change-existing-imagelist-image-size-of-listview
            /*
                When you change the size of an already initialized imagelist, using ImageSize, unfortunately all handles are destroyed, and previous images are not available anymore. But, if you save your images in a temporary collection, you can reset the existing ImageList and inject again all previous icons with the proper key. My code is the following:            
            */
            var OldImages = new Dictionary<string, Image>();
            foreach (string imgKey in imageList.Images.Keys)
            {
                OldImages.Add(imgKey, imageList.Images[imgKey]);
            }
            imageList.ImageSize = new Size(newSize, newSize);
            imageList.Images.Clear();
            foreach (string imgKey in OldImages.Keys)
            {
                imageList.Images.Add(imgKey, OldImages[imgKey]);
            }
        }

發表迴響

你的電子郵件位址並不會被公開。 必要欄位標記為 *