110,534
社区成员
发帖
与我相关
我的任务
分享
public Form4()
{
InitializeComponent();
//程序加载时保存Image文件夹下(包括子文件)所有图片路径
LoadPictureRoute();
//显示初始图片
pictureBox1.Image = new Bitmap(picList[CurrentID]);
}
//定义图片保存的地址的集合
List<string> picList = new List<string>();
//当前图片的下标
private int currentID;
public int CurrentID
{
get
{
return currentID; //返回当前图片下标
}
set
{
//如果当前图片的个数小于最小值,就让它的下标为最后一张图
if (value < 0) value = picList.Count - 1;
//如果当前图片的个数大于最大值,就让它的下标为第一张图
if (value > picList.Count - 1) value = 0;
//设置当前图片的下标
currentID = value;
}
}
/// <summary>
/// 将程序根目录和子文件夹的所有图片保存在一个List<string>中
/// </summary>
private void LoadPictureRoute()
{
//图片路径
string path = AppDomain.CurrentDomain.BaseDirectory + @"Image\";
//筛选png jpg bmp格式的图片并保存他们的地址
picList = Directory.GetFiles(path,"*.*",SearchOption.AllDirectories).Where(s=>s.EndsWith(".png")||s.EndsWith(".jpg")||s.EndsWith(".bmp")).ToList();
}
private void btnLast_Click(object sender, EventArgs e)
{
//显示上一张图片
CurrentID--;
pictureBox1.Image = new Bitmap(picList[CurrentID]);
}
private void btnNext_Click(object sender, EventArgs e)
{
//显示下一张图片
CurrentID++;
pictureBox1.Image = new Bitmap(picList[CurrentID]);
}
public Form4()
{
InitializeComponent();
LoadPictureRoute();
}
List<string> picList = new List<string>();
private int currentID;
public int CurrentID
{
get
{
return currentID;
}
set
{
if (value < 0) value = picList.Count - 1;
if (value > picList.Count - 1) value = 0;
currentID = value;
}
}
private void LoadPictureRoute()
{
string path = AppDomain.CurrentDomain.BaseDirectory + @"Image\";
var aggregate = Directory.GetFiles(path,"*.*",SearchOption.AllDirectories).Where(s=>s.EndsWith(".png")||s.EndsWith(".jpg")||s.EndsWith(".bmp"));
foreach (var item in aggregate)
{
picList.Add(item);
}
}
private void btnLast_Click(object sender, EventArgs e)
{
pictureBox1.Image = new Bitmap(picList[CurrentID--]);
}
private void btnNext_Click(object sender, EventArgs e)
{
pictureBox1.Image = new Bitmap(picList[CurrentID++]);
}