C#图片查看器实现方法

作者:彬菌 时间:2021-06-17 16:50:03 

实现效果:

C#图片查看器实现方法

注意:using system.io; 往Form1上添加控件picturebox,再添加imagelist,并设置imagelist的imagesize大小

Form1.cs代码:


using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.IO;

namespace ImageCheck
{
public partial class Form1 : Form
{
 public Form1()
 {
  InitializeComponent();
 }
 int index;
 private void button1_Click(object sender, EventArgs e)
 {
  index--;
  if (index<0)
  {
   MessageBox.Show("去往最后一张图片");
   index = imageList1.Images.Count - 1;
  }
  this.pictureBox1.Image = this.imageList1.Images[index];
 }

private void button2_Click(object sender, EventArgs e)
 {
  index++;
  if (index>imageList1.Images.Count-1)
  {
   MessageBox.Show("回到第一张图片");
   index = 0;
  }
  this.pictureBox1.Image = this.imageList1.Images[index];
 }

private void LoadImage()
 {
  string rootPath = Application.StartupPath;
  string filePath = rootPath + @"\image";
  DirectoryInfo rootDir = new DirectoryInfo(filePath);
  FileInfo[] file = rootDir.GetFiles();
  for (int i=0;i<=file.Length-1;i++)
  {
   Image img = Image.FromFile(file[i].FullName);
   this.imageList1.Images.Add(img);
  }
 }

private void Form1_Load(object sender, EventArgs e)
 {
  LoadImage();
  this.pictureBox1.Image = this.imageList1.Images[index];
 }
}
}

注意:在C#的工作目录Debug下创建image文件夹,并放置图片

来源:https://www.idaobin.com/archives/985.html

标签:C#,图片查看器
0
投稿

猜你喜欢

  • 处理java异步事件的阻塞和非阻塞方法分析

    2023-04-16 05:06:01
  • Java中的显示锁ReentrantLock使用与原理详解

    2021-11-14 07:04:00
  • Java经验点滴:类注释文档编写方法

    2023-11-06 03:50:11
  • java实现Dijkstra最短路径算法

    2022-11-30 21:02:15
  • 深入解析Java的Spring框架中bean的依赖注入

    2023-12-20 18:50:52
  • 关于Mybatis与JPA的优缺点说明

    2023-08-23 22:28:33
  • 详解Swagger接口文档和常用注解的使用

    2023-11-24 15:35:21
  • Spring boot配置文件加解密详解

    2023-11-12 00:17:29
  • C#知识整理

    2021-08-02 18:24:26
  • Spring JPA find分页示例详解

    2023-05-09 00:36:46
  • springboot调用支付宝第三方接口(沙箱环境)

    2023-11-25 06:12:08
  • Java十分钟精通类 封装 继承

    2023-11-25 10:55:58
  • 深入探讨JAVA中的异常与错误处理

    2023-06-11 00:30:24
  • java 中 poi解析Excel文件版本问题解决办法

    2023-11-15 16:49:45
  • 图文详解SpringBoot中Log日志的集成

    2023-05-27 09:55:13
  • elasticsearch分布式及数据的功能源码分析

    2023-08-11 06:31:26
  • Spring中事务几个常见的问题解决

    2022-04-07 00:52:01
  • tk.Mybatis 插入数据获取Id问题

    2023-07-01 22:03:13
  • 浅谈Java的两种多线程实现方式

    2022-08-17 09:42:37
  • 详解Spring-boot中读取config配置文件的两种方式

    2021-07-04 15:52:55
  • asp之家 软件编程 m.aspxhome.com