关于c#的OpenFileDialog,同时选择多个图片,同时可以翻页预览

窗体设计器中有一个OpenFileDialog,一个Picturebox,3个Button,其中一个Button是打开图片文件对话框,如果选择多个图片,然后用另外两个Button作为前后翻页的按钮,就是说一个是往后翻选中的图片,一个是往前翻选中的图片

 

代码如下:

 

 

private void Form1_Load(object sender, System.EventArgs e)
  {
   openFileDialog1.Multiselect=true;//允许同时选择多个文件
  }
        string[] picArr;//选择多张图片路径保存到数组
  private void button1_Click(object sender, System.EventArgs e)
  {
   if(openFileDialog1.ShowDialog()==DialogResult.OK)
   {
    picArr=openFileDialog1.FileNames;
    //pictureBox1.Image=Image.FromFile(picArr[0]);
   }
  }
        int i=0;
  private void button2_Click(object sender, System.EventArgs e)
  {
    i--;//上一张
    if(i<0)i=0;
    pictureBox1.Image=Image.FromFile(picArr[i]);
  }

  private void button3_Click(object sender, System.EventArgs e)
  {
       i++;//下一张
       if(i>picArr.Length-1)i=picArr.Length-1;
       pictureBox1.Image=Image.FromFile(picArr[i]);
  }

 

  • 1
    点赞
  • 11
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值