C#圖片查看器實(shí)現(xiàn)方法
實(shí)現(xiàn)效果:

注意:using system.io; 往Form1上添加控件picturebox,再添加imagelist,并設(shè)置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下創(chuàng)建image文件夾,并放置圖片
相關(guān)文章
C#采用FileSystemWatcher實(shí)現(xiàn)監(jiān)視磁盤文件變更的方法
這篇文章主要介紹了C#采用FileSystemWatcher實(shí)現(xiàn)監(jiān)視磁盤文件變更的方法,詳細(xì)分析了FileSystemWatcher的用法,并以此為基礎(chǔ)實(shí)現(xiàn)監(jiān)視磁盤文件變更,是非常實(shí)用的技巧,具有一定的借鑒價(jià)值,需要的朋友可以參考下2014-11-11
C#實(shí)現(xiàn)基于任務(wù)的異步編程模式
本文詳細(xì)講解了C#實(shí)現(xiàn)基于任務(wù)的異步編程模式,文中通過示例代碼介紹的非常詳細(xì)。對大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2022-04-04
C# DataTable中Compute方法用法集錦(數(shù)值/字符串/運(yùn)算符/表等操作)
這篇文章主要介紹了C# DataTable中Compute方法用法,總結(jié)分析了DataTable中Compute方法常見的數(shù)值運(yùn)算操作、字符串操作、運(yùn)算符操作、表運(yùn)算等相關(guān)技巧,需要的朋友可以參考下2016-06-06
C#實(shí)現(xiàn)將PDF轉(zhuǎn)為Excel的方法詳解
通常,PDF格式的文檔能支持的編輯功能不如office文檔多,針對PDF文檔里面有表格數(shù)據(jù)的,如果想要編輯表格里面的數(shù)據(jù),可以將該P(yáng)DF文檔轉(zhuǎn)為Excel格式。本文將介紹如何利用C#實(shí)現(xiàn)PDF轉(zhuǎn)Excel,需要的可以參考一下2022-04-04
C#實(shí)現(xiàn)數(shù)據(jù)包加密與解密實(shí)例詳解
這篇文章主要介紹了C#實(shí)現(xiàn)數(shù)據(jù)包加密與解密的方法,是一項(xiàng)很實(shí)用的技能,需要的朋友可以參考下2014-07-07

