【c#】如何编写当鼠标点击PictureBox控件是时候切换多张图片

2024-11-29 19:42:49
推荐回答(3个)
回答(1):

把一楼的哥们东西改一下给你
private readonly List imageList = new List
{
//三张图片的地址
@"e:\1.jpg",
@"e:\2.jpg",
@"e:\3.jpg"
};

public int currIndex=0;//索引值
private void button1_Click(object sender, EventArgs e)

if (currIndex >= imageList.Count)
{
currIndex = 0;
}
pictureBox1.Image = Image.FromFile(imageList[currIndex],true);
currIndex += 1;


这代码应该直接可以用

回答(2):

给出代码

public partial class Form1 : Form
{
private readonly List imageList = new List
{
@"e:\1.jpg",
@"e:\2.jpg",
@"e:\3.jpg"
};
private int currIndex = 0;
public Form1()
{
InitializeComponent();
}
private void pictureBox1_Click(object sender, EventArgs e)
{
if (currIndex >= imageList.Count)
currIndex = 0;
pictureBox1.Image = Image.FromFile(imageList[currIndex],true);
currIndex += 1;
}
}

回答(3):

使用imagelist 在按钮事件中写
this.pictureBox1.Image = this.imageList1.Images[i];
改变i就可以了 判断如果i最大了就设置为0