C#圖片查看器實(shí)現(xiàn)方法
更新時(shí)間:2018年03月27日 08:48:32 作者:彬菌
本篇文章給大家分享了用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)文章
詳解如何實(shí)現(xiàn)C#和Python間實(shí)時(shí)視頻數(shù)據(jù)交互
我們?cè)谧鯮TSP|RTMP播放的時(shí)候,遇到好多開(kāi)發(fā)者,他們的視覺(jué)算法大多運(yùn)行在python下,需要高效率的實(shí)現(xiàn)C#和Python的視頻數(shù)據(jù)交互,本文給大家總結(jié)了一些常用的方法,感興趣的小伙伴跟著小編一起來(lái)看看吧2024-10-10
C#中讓控件全屏顯示的實(shí)現(xiàn)代碼(WinForm)
有時(shí)候需要讓窗口中某一塊的內(nèi)容全屏顯示,比如視頻播放、地圖等等。經(jīng)過(guò)摸索,暫時(shí)發(fā)現(xiàn)兩種可行方法,如果有誰(shuí)知道其他方法,敬請(qǐng)告知2012-04-04
C#代碼設(shè)置開(kāi)機(jī)啟動(dòng)示例
本文介紹了使用C#代碼設(shè)置開(kāi)機(jī)啟動(dòng)的方法,原理就是在注冊(cè)表啟動(dòng)項(xiàng)里添加一項(xiàng)2014-01-01
C# List中FindAll用法的一些簡(jiǎn)單示例
本篇文章只要是對(duì)C# List中FindAll用法的一些簡(jiǎn)單示例進(jìn)行了介紹,需要的朋友可以過(guò)來(lái)參考下,希望對(duì)大家有所幫助2014-01-01
c#實(shí)現(xiàn)一個(gè)超實(shí)用的證件照換底色小工具(附源碼)
這篇文章主要給大家介紹了關(guān)于利用c#實(shí)現(xiàn)一個(gè)超實(shí)用的證件照換底色小工具的相關(guān)資料,通過(guò)這個(gè)小工具大家可以很方便的進(jìn)行底色的切換,不用再因?yàn)榈咨脑蝾^疼了,需要的朋友可以參考借鑒,下面來(lái)一起學(xué)習(xí)學(xué)習(xí)吧。2018-01-01

