Strange .NET ListView behaviour

I'm trying to get my head around this behaviour: I have a ListView on a form in LargeIcon View (System.Windows.Forms.View.LargeIcon)

This line is in the constructor:

this.listView1.LargeImageList.ImageSize = new Size(32, 32);

And then this function is called upon a double click:

private void listView1_DoubleClick(object sender, EventArgs e)
{
    this.listView1.LargeImageList.ImageSize = new Size(64, 64); 
}

When I double click on the listview, the size changes as expected, but the icon I have is taken away, and I just get a big blank space. Even if I set the ImageIndex to use afterwards, it stays blank, and I can't seem to get it displaying again.

I assume I'm doing something wrong (although I guess .NET could be broken). What do I change such that the icon does not disappear?

(I am in .NET 2.0)

13.10.2009 00:05:37
I take it you have an icon of the appropriate size? (64, 64) ?
Noon Silk 13.10.2009 00:07:17
No, all the icons are (200,200), but it works in the first place for (32, 32)
Smashery 13.10.2009 00:11:39
1 ОТВЕТ
РЕШЕНИЕ

I think you are running into this caveat described in MSDN (http://msdn.microsoft.com/en-us/library/system.windows.forms.imagelist.imagesize.aspx):

Because setting the ImageSize property causes the handle to be recreated, you should set ImageSize prior to setting the Images property.

Besides, relying on the system to resize the images from 32x32 to 64x64 would naturally result in low quality images.

2
13.10.2009 00:12:09
Yeah, I'm not concerned about the low-quality images as I'm just prototyping at the moment. It's more just that the images disappear and I can't get them to display again. It appears that the caveat you describe is indeed the problem - would this then mean that I have to recreate the set of images every time I wish to change the size of the icons?
Smashery 13.10.2009 00:18:34