我试图在 ListView 处于事件状态并包含项目时更改图像列表图像大小。但似乎只影响新添加的图像,现有图像会变成空白。
这是我的代码:
public Form1()
{
...
imglst_ = new ImageList();
imglst_.ImageSize = new Size(80, 80);
listView1.SmallImageList = imglst_;
listView1.LargeImageList = imglst_;
...
}
//zoom in
//This code only affect the new added image
//the existing images will become blank
private void toolStripZoomin_Click(object sender, EventArgs e)
{
int w = imglst_.ImageSize.Width;
int h = imglst_.ImageSize.Height;
w = (int)(w * 1.2);
h = (int)(h * 1.2);
imglst_.ImageSize = new Size(w, h);
}
最佳答案
ImageSize
的文档属性状态:
Setting the
ImageSize
property prior to adding images to the image collection causes the images to be resized to the image size specified.When you set the
ImageSize
property to a new value, theHandle
for the image list is recreated.Because setting the
ImageSize
property causes the handle to be recreated, you should set ImageSize prior to setting the Images property. When the handle for theImageList
has been created, setting theColorDepth
orImageSize
properties in code, after setting the Images property, will cause the collection of images set for the Images property to be deleted.
所以添加图片后不能更改ImageSize
,应在设置ImageSize
后再次将图片添加到ImageList
中因此它们将以新指定的尺寸绘制。
关于c# - 如何更改 Listview 的现有 Imagelist 图像大小,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43301283/