C#用imageList控件实现图片切换上下张
共有8张图片存放在imageList1,显示在pictureBox1button2换下一张,button1上一张,到尾端会跳回第一张我是这样写的,但顺序会出错inti=0...
共有8张图片存放在imageList1,显示在pictureBox1
button2换下一张,button1上一张,到尾端会跳回第一张
我是这样写的,但顺序会出错
int i = 0;
private void button2_Click(object sender, EventArgs e)
{
pictureBox1.Image = imageList1.Images[i];
i++;
if (i>= imageList1.Images.Count)i=0;
}
private void button1_Click(object sender, EventArgs e)
{
pictureBox1.Image = imageList1.Images[i];
i--;
if (i >= imageList1.Images.Count) i = 0;
if (i < 0) i = 7;
只能使用imageList控件,请求指点 展开
button2换下一张,button1上一张,到尾端会跳回第一张
我是这样写的,但顺序会出错
int i = 0;
private void button2_Click(object sender, EventArgs e)
{
pictureBox1.Image = imageList1.Images[i];
i++;
if (i>= imageList1.Images.Count)i=0;
}
private void button1_Click(object sender, EventArgs e)
{
pictureBox1.Image = imageList1.Images[i];
i--;
if (i >= imageList1.Images.Count) i = 0;
if (i < 0) i = 7;
只能使用imageList控件,请求指点 展开
1个回答
展开全部
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
int i = -1;
public Form1()
{
InitializeComponent();
}
//上一张按钮
private void button1_Click(object sender, EventArgs e)
{
if (i == 0)
{
i = imageList1.Images.Count - 1;
pictureBox1.Image = imageList1.Images[i];
}
else
{
i--;
pictureBox1.Image = imageList1.Images[i];
}
}
//下一张按钮
private void button2_Click(object sender, EventArgs e)
{
if (i == imageList1.Images.Count - 1)
{
i = 0;
pictureBox1.Image = imageList1.Images[i];
}
else
{
i++;
pictureBox1.Image = imageList1.Images[i];
}
}
}
}
{
public partial class Form1 : Form
{
int i = -1;
public Form1()
{
InitializeComponent();
}
//上一张按钮
private void button1_Click(object sender, EventArgs e)
{
if (i == 0)
{
i = imageList1.Images.Count - 1;
pictureBox1.Image = imageList1.Images[i];
}
else
{
i--;
pictureBox1.Image = imageList1.Images[i];
}
}
//下一张按钮
private void button2_Click(object sender, EventArgs e)
{
if (i == imageList1.Images.Count - 1)
{
i = 0;
pictureBox1.Image = imageList1.Images[i];
}
else
{
i++;
pictureBox1.Image = imageList1.Images[i];
}
}
}
}
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询