2017-04-08 102 views
1

我试图在列表视图处于活动状态并且包含项目时更改图像列表图像大小。但它似乎只影响新添加的图像,现有的图像将变为空白。如何更改列表视图的现有图像列表的图像大小

这里是我的代码:

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); 
} 

回答

0

ImageSize财产状态的文档:

ImageSize属性将图像添加到图像采集前的设置会导致图像被调整到图像指定大小。

当您将ImageSize属性设置为新值时,会重新创建Handle的 图像列表。

由于设置ImageSize财产造成把手是 重建,你应该设置IMAGESIZE之前设置图像 财产。当已经创造了ImageList手柄,设置 代码中的ColorDepthImageSize性质,设置 Images属性之后,将会给 图像属性中删除图像集的集合。

所以你不能添加图像后更改ImageSize,你应该在设置ImageSize所以他们会在新指定的尺寸绘制后重新添加图像到ImageList