![]() |
#2
yhlvht2016-12-05 13:39
|
只有本站会员才能查看附件,请 登录
一个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];
}
{
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集合添加的两张图片
只有本站会员才能查看附件,请 登录
调试的情况如下:
只有本站会员才能查看附件,请 登录
只有本站会员才能查看附件,请 登录
请问各位前辈,为什么下标没有有效值?