private void Form1_Load(object sender, EventArgs e)
{
string path = Application.StartupPath.Substring(0,Application.StartupPath.Substring(0,Application.StartupPath.LastIndexOf("\\")).LastIndexOf("\\"));
path += @"\01.jpg";
string path2 = Application.StartupPath.Substring(0, Application.StartupPath.Substring(0, Application.StartupPath.LastIndexOf("\\")).LastIndexOf("\\"));
path2 += @"\02.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)
{
int a = 0;
if (a == (imageList1.Images.Count - 1))
{
a = 0;
}
else if(a<imageList1.Images.Count)
{
a = a + 1;
} this.pictureBox1.Image=this.imageList1.Images[a];
} 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 += @"\01.jpg";
string path2 = Application.StartupPath.Substring(0, Application.StartupPath.Substring(0, Application.StartupPath.LastIndexOf("\\")).LastIndexOf("\\"));
path2 += @"\02.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)
{
int a = 0;
if (a == (imageList1.Images.Count - 1))
{
a = 0;
}
else if(a<imageList1.Images.Count)
{
a = a + 1;
} this.pictureBox1.Image=this.imageList1.Images[a];
} private void button2_Click(object sender, EventArgs e)
{
pictureBox1.Image = imageList1.Images[1];
}
}这是代码那里出错了啊,请大家帮忙
解决方案 »
- 在cs中编写的js,为什么不执行?
- winform 上传文件至数据库
- 如何用窗体中(如在Load事件中)执行如 ngen C:\mRelease\myinfoapp.exe的Vs2008的Dos命令呢?注意不是Cmd.exe的 否则会出现ngen不是内部命令
- 超级难题:如何用MS SQL API(SQLDMO.dll)存取image字段
- 请教大家一个问题?
- 一个简单问题大家来看看
- SQL server 2000 Reporting Services安装问题
- 在C#.net中使用 Fast Report
- C语言结构体中的 数组的参数
- 调用excel的pagesetup为什么报“没有安装打印机”
- c#开发winform时Process调用exe程序,win7下毫无问题,XP下运行不了
- 如何property的类型,调用泛型方法?
最前,这三处加上 Console.WriteLine(imageList1.Images.Count); 出错时看看控制台输出了什么。
这句话是干嘛啊,好像是不是使用错误了
我曾经也使用过ImageList,用下标取的时候,也是取不出来,也不知道什么原因;不过有解决办法:
Image ming2 = Image.FromFile(path2, true);
imageList1.Images.Add(ming2);
你添加的时候这样子添加:
imageList1.Images.Add("ming2",ming2);
给它添加一个key进去
取的时候通过key来取
例如
imageList1["ming2"]这样子就可以取出来了。
很奇怪,我怀疑是.net的bug
imageList1.Images.Add("2", ming2);
不是写了个例子嘛,添加的时候,如楼上:imageList1.Images.Add("1", ming);
取的时候,imageList1["1"]这样取