菜鸟求picture box一个问题,解决马上给分
在form1放一个picture box,form1同级目录中有300张图片,分别人1.jpg,2.jpg...300.jpg,在form1中有四个按钮分别为上一张图,下一张图,第一张图和下一张图。要求实现点各按钮实现显示所对应的图片
------解决方案--------------------把图片都Copy到程序运行目录Debug下:
代码粗略如下:
Private int i=0;j=0;
private void First_Click(object sender, EventArgs e)
{
string images = "1.jpg ";
pictureBox1.Image = Image.FromFile(images);
i = 0;
}
private void Preview_Click(object sender, EventArgs e)
{
if (j> =1&&j <301)
{
j--;
string images = i.ToString() + ".jpg ";
pictureBox1.Image = Image.FromFile(images);
i = j;
}
}
private void Next_Click(object sender, EventArgs e)
{
if (i > = 0 && i <301)
{
i++;
string images = i.ToString() + ".jpg ";
pictureBox1.Image = Image.FromFile(images);
j = i;
}
}
private void End_Click(object sender, EventArgs e)
{
string images = "300.jpg ";
pictureBox1.Image = Image.FromFile(images);
i = 300;
j = 300;
}