1,界面如下
2,代码如下
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace _10图片加页减页
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
/// <summary>
/// 在刚刚开始时就显示一张图片
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void Form1_Load(object sender, EventArgs e)
{
pictureBox1.Image = Image.FromFile(@"C:\Users\liangyue\Desktop\visonpron 训练\1\1.bmp");
}
int i = 0;//非常重要,因为一开始是想不到的,所以我们这是一个思想转化的流程
string[] str = Directory.GetFiles(@"C:\Users\liangyue\Desktop\visonpron 训练\1", "*.bmp");//非常重要,相当于把文件夹标出来,给我们找
private void button2_Click(object sender, EventArgs e)
{
i++;
if(i==str.Length)
{
i = 0;
}
pictureBox1.Image = Image.FromFile(str[i]);
}
private void button1_Click(object sender, EventArgs e)
{
i--;
if (i<0)
{
i = str.Length-1;
}
pictureBox1.Image = Image.FromFile(str[i]);
}
}
}