http://msdn.microsoft.com/en-us/library/system.windows.forms.imagelist.imagesize.aspx[
^]
In the remark section it says: Setting the ImageSize property prior to adding images to the image collection causes the images to be resized to the image size specified. I would suggest you to store all the images in separate member of type List
. Whenever you add an image to your ImageList, you add the same Image here also.
List<Image> actualImageList;
public Form1()
{
InitializeComponent();
actualImageList = new List<Image>();
}
And so
case TwainCommand.TransferReady:
...
for (int j = 0; j < this.imageList1.Images.Count; j++)
{
ListViewItem item = new ListViewItem();
item.ImageIndex = j;
this.listView1.Items.Add(item);
this.actualImageList.Add(item);
}
Display the coressponding image from the actualImageList instead
Note: The code you've added to this function is kind of messy. You are iterating on a collection and changing the same properties of the same pictureBox1. In the result it will end up displaying the last checked image. Anyway, I didn't correct the code, as I have no information about your requirements.
private void listView1_SelectedIndexChanged(object sender, EventArgs e)
{
for (int k = 0; k < listView1.CheckedIndices.Count; k++)
{
pictureBox1.Image = actualImageList[CheckedIndices[k]];
pictureBox1.Visible = true;
pictureBox1.Size = new Size(200, 256);
}
}
Remember that the ImageList class is designed to store images of the same size, and especially for ListView control it has to be mostly used for displaying the items.
For deleting I would suggest the following method.
private void DeleteChecked()
{
while (listView1.CheckedItems.Count > 0)
{
ListViewItem item = listView1.CheckedItems[0];
imageList1.Images.RemoveAt(item.ImageIndex);
actualImageList.RemoveAt(item.ImageIndex);
listView1.Items.Remove(item);
}
}