[英](C#, WinForms) How to assign an accessibility attribute to an image in ImageList
[英]How can I replace an existing image on a winforms ImageList?
如何替换Winforms ImageList
上的现有图像?
我尝试了这个:
this.CoolPics.Images [ 2 ] = // new image
this.ListViewControl.SmallImageList = this.CoolPics;
但是,当我使用this.CoolPics.Images.Add
方法时,新图像不会像其他图像那样重新缩放。
我究竟做错了什么?
我知道这很老,但是这是我解决问题的方法。 看起来图像列表在分配时不会调整图像的大小(即使使用Add()函数时也是如此)。 因此,基本上,您需要在分配之前手动调整图像的大小。
Image img; //used to load new image from disk
Bitmap bmp = new Bitmap(160, 120); //canvas where the new image will be drawn/resized
Graphics graph = Graphics.FromImage(bmp); //used to draw/resize the new image
img = new Bitmap(fileDialog.FileNames[0]); //load new image from disk
graph.DrawImage(img, new Rectangle(0, 0, 160, 120)); //resize new image to proper size
imgList.Images[index] = bmp; //assign the new resized image to the list (overwrites the old image)
您的代码后尝试
listView1.Refresh();
我之前碰到过这个问题,如果我没记错的话,赋值运算符也有这种行为,但是Imagelist.Images.Add(myImage)做正确的事情。
尝试更改代码以执行.Add(myImage),看看效果是否更好。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.