注册 登录
编程论坛 C# 论坛

求助:InvalidArgument=“0”的值对于“index”无效

lanke711 发布于 2016-12-04 20:49, 3611 次点击
只有本站会员才能查看附件,请 登录

一个pictureBox控件,一个imagelist控件,两个Button

代码如下:
程序代码:
private void Form1_Load(object sender, EventArgs e)
        {
            string Path = Application.StartupPath.Substring(0,Application.StartupPath.Substring(0,Application.StartupPath.LastIndexOf("\\")).LastIndexOf("\\"));
            Path += @"\11.jpg";
            string Path2 = Application.StartupPath.Substring(0, Application.StartupPath.Substring(0, Application.StartupPath.LastIndexOf("\\")).LastIndexOf("\\"));
            Path2 += @"\22.jpg";
            Image Ming = Image.FromFile(Path,true);
            imageList1.Images.Add(Ming);
            Image Ming2 = Image.FromFile(Path2, true);
            imageList1.Images.Add(Ming2);
            imageList1.ImageSize = new Size(200,165);
            pictureBox1.Width = 200;
            pictureBox1.Height = 165;
        }

        private void button1_Click(object sender, EventArgs e)
        {
            pictureBox1.Image = imageList1.Images[0];
        }

        private void button2_Click(object sender, EventArgs e)
        {
            pictureBox1.Image = imageList1.Images[1];
        }


运行时,出现这个异常提示

只有本站会员才能查看附件,请 登录


这是ImageList控件的Image集合添加的两张图片
只有本站会员才能查看附件,请 登录


调试的情况如下:
只有本站会员才能查看附件,请 登录


只有本站会员才能查看附件,请 登录


请问各位前辈,为什么下标没有有效值?
1 回复
#2
yhlvht2016-12-05 13:39
因为你加入图片后改变了imagesize,导致你先加的图片用不了,先改变imagesize,再加入图片就可以了
1