【问题标题】:How to Change existing Imagelist image size of Listview如何更改 Listview 的现有 Imagelist 图像大小
【发布时间】:2017-04-09 07:19:36
【问题描述】:

我正在尝试在 listview 处于活动状态并包含项目时更改 imagelist 图像大小。但是好像只影响新添加的图片,现有的图片会变成空白。

这是我的代码:

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

【问题讨论】:

    标签: c#


    【解决方案1】:

    ImageSize 属性的文档说明:

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

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

    因为设置ImageSize 属性会导致句柄 重新创建,您应该在设置图像之前设置 ImageSize 属性。ImageList 的句柄已创建,设置 代码中的ColorDepthImageSize 属性,设置后 图像属性,将导致图像集合为 要删除的图像属性。

    所以你不能在添加图片后更改ImageSize,你应该在设置ImageSize之后再次将图片添加到ImageList,以便它们以新指定的大小绘制。

    【讨论】:

      猜你喜欢
      • 2012-01-12
      • 2014-10-31
      • 2021-12-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多