怎样能用picturebox切换图片 就是有一个按钮上一张 下一张那样

private void 相册浏览_Click(object sender, EventArgs e)
   {//private Bitmap SourceBitmap, MyBitmap;
   OpenFileDialog 打开文件 = new OpenFileDialog(); this.图像显示.Image = null;//打开图像文件//打开文件.Multiselect = true;
   打开文件.Filter = "图像文件(JPeg, Gif, Bmp, etc.)|*.jpg;*.jpeg;*.gif;*.bmp;*.tif; *.tiff; *.png|"
   + " JPeg 图像文件(*.jpg;*.jpeg)|*.jpg;*.jpeg |GIF 图像文件(*.gif)|*.gif |BMP图像文件(*.bmp)|*.bmp|"
   + "Tiff图像文件(*.tif;*.tiff)|*.tif;*.tiff|Png图像文件(*.png)| *.png |所有文件(*.*)|*.*";
   if (打开文件.ShowDialog() == DialogResult.OK) { 显示图像(打开文件.FileName); 上一图.Enabled = false; 下一图.Enabled = false; } else { 上一图.Enabled = true; 下一图.Enabled = true; }
   FolderBrowserDialog 文件夹 = new FolderBrowserDialog(); 文件夹.Description = "请选择图像文件夹路径:";
   if (this.Text.IndexOf("^") >= 0)
   {
   if (图像文件表 == null)
   {
   string[] 设备目录 = this.Text.Split(new char[2] { '[', ']' });
   String 保存路径 = @System.Environment.CurrentDirectory + "\\设备相册集\\" + 设备目录[1];
   保存路径 = 保存路径.Replace("/", "\\"); System.Diagnostics.Process.Start("explorer.exe ", 保存路径);
   }
   }
   else
   { if (文件夹.ShowDialog() == DialogResult.OK) { 图数.Text = "没图?"; string 目录名 = @文件夹.SelectedPath; 遍历文件(目录名); } }
   //DirectoryInfo di = new DirectoryInfo(@"c:\MyDir");
   //try { if (di.Exists) { return; } di.Create(); di.Delete(); }
   //catch (Exception ee) { Console.WriteLine("The process failed: {0}", ee.ToString()); }
   //finally { }
   }

   private void 遍历文件(string 指定目录)
   {
   DirectoryInfo 目录 = new DirectoryInfo(指定目录);
   //DirectoryInfo[] 子目录集 = 目录.GetDirectories();
   //foreach (DirectoryInfo 读目 in 子目录集)
   //{
   // if (读目.Parent.ToString() == "Image") { }
   // FileInfo[] 文件列表 = 读目.GetFiles();
   // foreach (FileInfo 读件 in 文件列表) { }
   // DirectoryInfo[] 返回子目录 = 读目.GetDirectories();
   // if (返回子目录.Length > 0) { 遍历文件(读目.FullName); }
   //}
   //DirectoryInfo 目录 = new DirectoryInfo(指定目录);
   int i = 0; string 图类 = "*.JPG*.JPEG*.GIF*.BMP*.TIF*.TIFF*.PNG*.ICO*.jpg*.jpeg*.gif*.bmp*.tif*.tiff*.png*.ico";
   图像文件表 = new string[目录.GetFiles().Length - 目录.GetFiles("*.ini").Length];
   foreach (FileInfo 读名 in 目录.GetFiles())
   { if (图类.IndexOf(读名.Extension) >= 0) { 图像文件表[i] = 目录.FullName + "\\" + 读名.Name; i++; } }
   if (图像文件表.Length > 0 && 图像文件表[0] != null) { 显示图像(图像文件表[0]); 图数.Text = "1/" + 图像文件表.Length.ToString(); 上一图.Enabled = true; 下一图.Enabled = true; }
   }

   private void 显示图像(string 文件径名)
   {
   if (文件径名 != null)
   {
   Bitmap 原始图像 = new Bitmap(文件径名);//得到原始大小的图像
   if (图像显示.Width > 原始图像.Width) { 图像显示.Width = 原始图像.Width; this.图像显示.Image = 原始图像; }
   else if (图像显示.Height > 原始图像.Height) { 图像显示.Height = 原始图像.Height; this.图像显示.Image = 原始图像; }
   else//得到缩放后的图像
   { Bitmap 显示图象 = new Bitmap(原始图像, this.图像显示.Width, this.图像显示.Height); this.图像显示.Image = 显示图象; }
   }
   else { MessageBox.Show("该文件不是图形图像文件,无法显示浏览!", "错误提示"); }
   }
private void 上一图_Click(object sender, EventArgs e)
   {
   if (公共数[0] < 图像文件表.Length - 1 && 图像文件表 != null)
   { 公共数[0]++; if (图像文件表[公共数[0]] != null) { 显示图像(图像文件表[公共数[0]]); 图数.Text = (公共数[0] + 1).ToString() + "/" + 图像文件表.Length.ToString(); }
   else { if (公共数[0] == 图像文件表.Length) { MessageBox.Show("文件浏览已经到最后面!", "友情提示"); } else MessageBox.Show("该文件不是图形图像文件,无法显示浏览!", "错误提示"); } }
   }

   private void 下一图_Click(object sender, EventArgs e)
   {
   if (公共数[0] <= 图像文件表.Length && 公共数[0] > 0 && 图像文件表 != null)
   { 公共数[0]--; 显示图像(图像文件表[公共数[0]]); 图数.Text = (公共数[0] + 1).ToString() + "/" + 图像文件表.Length.ToString(); }
   else { if (公共数[0] == 0) { MessageBox.Show("文件浏览已经到最前面!", "友情提示"); } else { MessageBox.Show("该文件不是图形图像文件,无法显示浏览!", "错误提示"); } }
   }

   private void 图像显示_DoubleClick(object sender, EventArgs e)
   {
   FolderBrowserDialog 文件夹 = new FolderBrowserDialog(); 文件夹.Description = "请选择保存图像文件夹路径:";
   if (this.Text.IndexOf("^") >= 0)
   {
   string[] 设备目录 = this.Text.Split(new char[2] { '[', ']' });
   String 保存路径 = @System.Environment.CurrentDirectory + "\\设备相册集\\" + 设备目录[1];
   保存路径 = 保存路径.Replace("/", "\\"); System.Diagnostics.Process.Start("explorer.exe ", 保存路径);
   }
   else
   { if (文件夹.ShowDialog() == DialogResult.OK) { 图数.Text = "没图?"; string 目录名 = @文件夹.SelectedPath; 遍历文件(目录名); } }
   }

  • 4
    点赞
  • 9
    收藏
    觉得还不错? 一键收藏
  • 7
    评论
评论 7
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值