PictureBox:显示图像。
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
//设置图片如何在pictureBox1中显示
pictureBox1.SizeMode = PictureBoxSizeMode.CenterImage;
//显示指定路径的图片
pictureBox1.Image = Image.FromFile(path[i]);
}
//获得指定文件夹的所有文件的全路径
string[] path = Directory.GetFiles(@"C:\Users\46124\Desktop\Create one's own\Animation");
int i = 0;
/// <summary>
/// 点击更换下一张图片
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void buttonNext_Click(object sender, EventArgs e)
{
i++;
//如果已经是最后一张了,点击下一张,使i=0,回到最开始的一张
if (i == path.Length)
{
i = 0;
}
pictureBox1.Image = Image.FromFile(path[i]);
}
/// <summary>
/// 上一张图片
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void buttonLast_Click(object sender, EventArgs e)
{
i--;
//如果已经是第一张了,点击上一张,使i=path.Length-1,回到最后的一张
if (i == -1)
{
i = path.Length - 1;
}
pictureBox1.Image = Image.FromFile(path[i]);
}
private void button1_Click(object sender, EventArgs e)
{
this.Close();
}
}