PictureBox:显示图像。

    image.png

    1. public partial class Form1 : Form
    2. {
    3. public Form1()
    4. {
    5. InitializeComponent();
    6. }
    7. private void Form1_Load(object sender, EventArgs e)
    8. {
    9. //设置图片如何在pictureBox1中显示
    10. pictureBox1.SizeMode = PictureBoxSizeMode.CenterImage;
    11. //显示指定路径的图片
    12. pictureBox1.Image = Image.FromFile(path[i]);
    13. }
    14. //获得指定文件夹的所有文件的全路径
    15. string[] path = Directory.GetFiles(@"C:\Users\46124\Desktop\Create one's own\Animation");
    16. int i = 0;
    17. /// <summary>
    18. /// 点击更换下一张图片
    19. /// </summary>
    20. /// <param name="sender"></param>
    21. /// <param name="e"></param>
    22. private void buttonNext_Click(object sender, EventArgs e)
    23. {
    24. i++;
    25. //如果已经是最后一张了,点击下一张,使i=0,回到最开始的一张
    26. if (i == path.Length)
    27. {
    28. i = 0;
    29. }
    30. pictureBox1.Image = Image.FromFile(path[i]);
    31. }
    32. /// <summary>
    33. /// 上一张图片
    34. /// </summary>
    35. /// <param name="sender"></param>
    36. /// <param name="e"></param>
    37. private void buttonLast_Click(object sender, EventArgs e)
    38. {
    39. i--;
    40. //如果已经是第一张了,点击上一张,使i=path.Length-1,回到最后的一张
    41. if (i == -1)
    42. {
    43. i = path.Length - 1;
    44. }
    45. pictureBox1.Image = Image.FromFile(path[i]);
    46. }
    47. private void button1_Click(object sender, EventArgs e)
    48. {
    49. this.Close();
    50. }
    51. }