c#实现上一页和下一页功能
2021-04-02 05:24
标签:.sh lis fromfile ast led ESS pen his rom public partial class Form1 : Form string path = Path.GetDirectoryName(fileName); this.pictureBox1.Image = Image.FromFile(@fileName); } int index = 0; if (index == 1) this.pictureBox1.Image = Image.FromFile(fileLists[index-1]); private void BtnNextImage_Click(object sender, EventArgs e) if (index == fileLists.Length-1) c#实现上一页和下一页功能 标签:.sh lis fromfile ast led ESS pen his rom 原文地址:https://www.cnblogs.com/ww7018/p/9226303.html
{
private string[] fileLists = null;//定义FileList集合用来存储当前文件中的所有文件
private string fileName = "";//用户弹出对话框后选择的图片名称
public Form1()
{
InitializeComponent();
}
///
/// 从本地磁盘中获取图片资源
///
///
///
private void BtnOpenImg_Click(object sender, EventArgs e)
{
OpenFileDialog openDlg = new OpenFileDialog();
openDlg.Filter = "图片资源(*.png)|*.png|图片资源(*.jpg)|*.jpg|所有文件(*.*)|*.*";
openDlg.ShowDialog();
fileName = openDlg.FileName;
//MessageBox.Show("fileName=" + fileName);
//MessageBox.Show(path);
fileLists = Directory.GetFiles(path);//获取该路径下的所有文件
}
private void Form1_Load(object sender, EventArgs e)
{
this.pictureBox1.SizeMode = PictureBoxSizeMode.StretchImage;//设置图片的显示模式
bool isHasIndex = false;
private void BtnLastImage_Click(object sender, EventArgs e)
{
if (fileLists == null)
{
MessageBox.Show("请选择一张图片");
}
else
{
if (!isHasIndex)
{
for (int i = 0; i {
if (fileName == fileLists[i])
{
index = i;//给索引赋值
// MessageBox.Show("index=" + index);
isHasIndex = true;
}
}
}
{
index = fileLists.Length;
}
index--;
}
}
{
if (fileLists == null)
{
MessageBox.Show("请选择一张图片");
}
else
{
if (!isHasIndex)
{
for (int i = 0; i {
if (fileName == fileLists[i])
{
index = i;//给索引赋值
// MessageBox.Show("index=" + index);
isHasIndex = true;
}
}
}
{
index = 1;
}
this.pictureBox1.Image = Image.FromFile(fileLists[index+1]);
index++;
}
}
}