ImageList Images Disappearing

A

A. Solomon

Hi,

I have a ImageList containing 4 bitmaps attached to a UserControl
which acts as a Open/Close panel.

This panel, upon click, switches the image in a PictureBox control to
indicate the current panel status (Open/Close).

Problem is that in certain complex scenarios the images disappear!
from the ImageList. That is, when I call: imageList.Images[1], I get
the exception: Specified argument was out of the range of valid
values.
Parameter name: '1' is not a valid value for 'index'. And when I check
the length of the Images collection it turns out to be zero :-(

I have a faint clue regarding the cause of this problem - it may have
something to do with the visibility of the UserControl containing the
ImageList.

Has anyone seen something like that before?
 
S

Shakir Hussain

Solomon,

I am not quite sure, why ur imagelist behaves that way.

For time being you can do this,

try
{
//lets say you are trying to get a image here and for some reason
//it throws an execption
Image test = imageList.Images[1];
}
catch(Exception e)
{
//when the exception is thrown, reload the imagelist from resource.
this.imageList1.ImageStream =
((System.Windows.Forms.ImageListStreamer)(resources.GetObject("imageList1.Im
ageStream")));

}
 
J

John Wood

The images are populated into the imagelist during the initialization... if
you run any functions in the constructor before the imagelist has had a
chance to populate, then you may see this error.

I can't think of any other reason why you'd see this error at present...
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top