上位机界面
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 WindowsFormsApp1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
pictureBox1.SizeMode = PictureBoxSizeMode.StretchImage; //设置图片显示方式为自适应
pictureBox1.Image = Image.FromFile(@"C:\Users\zifeiyu\Desktop\Picture\45.Jpg"); //设置初始图片
}
string[] path = Directory.GetFiles(@"C:\Users\zifeiyu\Desktop\Picture");//获得指定路径下所有文件的全路径
int i = 0;
private void button2_Click(object sender, EventArgs e) //下一张
{
i++;
if (i==path.Length) //防止到最后一张时下标溢出
{
i = 0;
}
pictureBox1.Image = Image.FromFile(path[i]); //根据图片路径来更换图片
}
private void button1_Click(object sender, EventArgs e) //上一张
{
i--;
if (i <0) //防止到最后一张时下标溢出
{
i = path.Length-1;
}
pictureBox1.Image = Image.FromFile(path[i]); //根据图片路径来更换图片
}
}
}