1 回答

TA貢獻(xiàn)1864條經(jīng)驗(yàn) 獲得超2個(gè)贊
首先,您沒有在任何地方設(shè)置 _imageIndex,除了在 btnPrevious_Click 中將其設(shè)置為 0。
您需要在 SelectedIndexChanged 方法中將其設(shè)置為選定索引,如下所示(注意添加到您之前代碼中的最后一行):
private void listView1_SelectedIndexChanged(object sender, EventArgs e)
{
//FOR i is less than the first image.
for (int i = 0; i < listView1.SelectedItems.Count; i++)
{
//GET filename from listview and store in index.
_big_fileName = listView1.SelectedItems[i].Text;
//Create larger instance of image.
pictureBox1.Image = Image.FromFile(_big_fileName);
//Fill panel to the width and height of picture box.
panel1.AutoScrollMinSize = new Size(pictureBox1.Image.Width, pictureBox1.Image.Height);
_imageIndex = listView1.SelectedIndices[0];
}
}
接下來(lái),在 btnPreviousClick 中,您需要進(jìn)行一些更改:
private void btnPrevious_Click(object sender, EventArgs e)
{
if (pictureBox1.Image != null)
{
//IF Image is less than Image list size.
if (_imageIndex >= 0 && _imageIndex < imageList1.Images.Count)
{
//De-select current item
listView1.Items[_imageIndex].Selected = false;
//GO to previous entry.
_imageIndex--;
//Select new item
if(_imageIndex>=0){
listView1.Items[_imageIndex].Selected = true;
listView1.Select();
}
}
}
else
{
MessageBox.Show("No image.");
}
}
有必要在 listView1 上調(diào)用 Select() 方法。最大的問(wèn)題是你沒有設(shè)置 _imageIndex 。
- 1 回答
- 0 關(guān)注
- 249 瀏覽
添加回答
舉報(bào)