求助:InvalidArgument=“0”的值对于“index”无效
一个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集合添加的两张图片
调试的情况如下:
请问各位前辈,为什么下标没有有效值?