本篇文章给大家分享了用C#制作图片查看器的方法以及先实现代码,有需要的读者们参考下。
实现效果:
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文件夹,并放置图片
沃梦达教程
本文标题为:C#图片查看器实现方法


猜你喜欢
- c++ const 成员函数,返回一个 const 指针.但是返回的指针是什么类型的 const? 2022-10-11
- C语言手把手带你掌握带头双向循环链表 2023-04-03
- 详解C语言中sizeof如何在自定义函数中正常工作 2023-04-09
- Qt计时器使用方法详解 2023-05-30
- Easyx实现扫雷游戏 2023-02-06
- C语言qsort()函数的使用方法详解 2023-04-26
- C++ 数据结构超详细讲解顺序表 2023-03-25
- 我应该为我的项目使用相对包含路径,还是将包含目录放在包含路径上? 2022-10-30
- C语言详解float类型在内存中的存储方式 2023-03-27
- ubuntu下C/C++获取剩余内存 2023-09-18