第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問(wèn)題,去搜搜看,總會(huì)有你想問(wèn)的

C# 返回到列表視圖中的上一個(gè)圖像并將其顯示在圖片框中

C# 返回到列表視圖中的上一個(gè)圖像并將其顯示在圖片框中

C#
繁星點(diǎn)點(diǎn)滴滴 2021-07-15 18:04:10
我正在嘗試選擇列表視圖中的上一張圖像并將其顯示在右側(cè)的圖片框中。我正在使用 _imageIndex 來(lái)跟蹤當(dāng)前圖片框中的內(nèi)容,如果它小于圖像列表長(zhǎng)度,則我在列表視圖中選擇圖像并使用 _imageIndex 計(jì)數(shù)器訪問(wèn)圖像。但這就像根本沒有獲得圖像索引。它只是繼續(xù)在 0 處讀取它并將其遞減為負(fù) 1 并在我再次單擊 btnPrevious 時(shí)返回錯(cuò)誤。System.ArgumentOutOfRangeException: 'InvalidArgument=Value of '-1' is not valid for 'index'.Parameter name: index'我知道我在 mnuOpen_Click 事件中將其設(shè)置為 _imageIndex 為 0。除此之外我不知道如何解決這個(gè)問(wèn)題。為清楚起見,這里是GUI的圖像。請(qǐng)問(wèn)有什么想法嗎?public partial class Form1 : Form{    string _big_fileName;    int _counter = 0;    int _imageIndex;    public Form1()    {                    InitializeComponent();    }    //Displays larger instance of selected image in picture box.    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);        }    }    private void mnuOpen_Click(object sender, EventArgs e)    {                    loadImageList();        _imageIndex = 0;    }    private void btnPrevious_Click(object sender, EventArgs e)    {        if (pictureBox1.Image != null)        {                            //IF Image is less than Image list size.            if (_imageIndex < imageList1.Images.Count)            {                //SELECT  listview items with counter.                listView1.Items[_imageIndex].Selected = true;                //GO to previous entry.                _imageIndex--;            }        }        else        {            MessageBox.Show("No image.");        }    }
查看完整描述

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 。


查看完整回答
反對(duì) 回復(fù) 2021-07-17
  • 1 回答
  • 0 關(guān)注
  • 249 瀏覽

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)