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文件夾,并放置圖片
您可能感興趣的文章
- 01-10WinForm實(shí)現(xiàn)仿視頻播放器左下角滾動(dòng)新聞效果的方法
 - 01-10.net2.0+ Winform項(xiàng)目實(shí)現(xiàn)彈出容器層
 - 01-10C#實(shí)現(xiàn)打開(kāi)畫(huà)圖的同時(shí)載入圖片、最大化顯示畫(huà)圖窗體的方法
 - 01-10C#實(shí)現(xiàn)將窗體固定在顯示器的左上角且不能移動(dòng)的方法
 - 01-10C#編程獲取資源文件中圖片的方法
 - 01-10http圖片上傳安全性問(wèn)題 根據(jù)ContentType (MIME) 判斷其實(shí)不準(zhǔn)確、不
 - 01-10淺析JAVA中過(guò)濾器、監(jiān)聽(tīng)器、攔截器的區(qū)別
 - 01-10C#將圖片存放到SQL SERVER數(shù)據(jù)庫(kù)中的方法
 - 01-10C#日歷樣式的下拉式計(jì)算器實(shí)例講解
 - 01-10C#操作數(shù)據(jù)庫(kù)中存取圖片文件的方法
 


閱讀排行
- 1C語(yǔ)言 while語(yǔ)句的用法詳解
 - 2java 實(shí)現(xiàn)簡(jiǎn)單圣誕樹(shù)的示例代碼(圣誕
 - 3利用C語(yǔ)言實(shí)現(xiàn)“百馬百擔(dān)”問(wèn)題方法
 - 4C語(yǔ)言中計(jì)算正弦的相關(guān)函數(shù)總結(jié)
 - 5c語(yǔ)言計(jì)算三角形面積代碼
 - 6什么是 WSH(腳本宿主)的詳細(xì)解釋
 - 7C++ 中隨機(jī)函數(shù)random函數(shù)的使用方法
 - 8正則表達(dá)式匹配各種特殊字符
 - 9C語(yǔ)言十進(jìn)制轉(zhuǎn)二進(jìn)制代碼實(shí)例
 - 10C語(yǔ)言查找數(shù)組里數(shù)字重復(fù)次數(shù)的方法
 
本欄相關(guān)
- 01-10C#通過(guò)反射獲取當(dāng)前工程中所有窗體并
 - 01-10關(guān)于ASP網(wǎng)頁(yè)無(wú)法打開(kāi)的解決方案
 - 01-10WinForm限制窗體不能移到屏幕外的方法
 - 01-10WinForm繪制圓角的方法
 - 01-10C#實(shí)現(xiàn)txt定位指定行完整實(shí)例
 - 01-10WinForm實(shí)現(xiàn)仿視頻播放器左下角滾動(dòng)新
 - 01-10C#停止線程的方法
 - 01-10C#實(shí)現(xiàn)清空回收站的方法
 - 01-10C#通過(guò)重寫(xiě)Panel改變邊框顏色與寬度的
 - 01-10C#實(shí)現(xiàn)讀取注冊(cè)表監(jiān)控當(dāng)前操作系統(tǒng)已
 
隨機(jī)閱讀
- 01-11ajax實(shí)現(xiàn)頁(yè)面的局部加載
 - 01-10delphi制作wav文件的方法
 - 08-05織夢(mèng)dedecms什么時(shí)候用欄目交叉功能?
 - 08-05dedecms(織夢(mèng))副欄目數(shù)量限制代碼修改
 - 04-02jquery與jsp,用jquery
 - 01-10SublimeText編譯C開(kāi)發(fā)環(huán)境設(shè)置
 - 01-10C#中split用法實(shí)例總結(jié)
 - 01-10使用C語(yǔ)言求解撲克牌的順子及n個(gè)骰子
 - 01-11Mac OSX 打開(kāi)原生自帶讀寫(xiě)NTFS功能(圖文
 - 08-05DEDE織夢(mèng)data目錄下的sessions文件夾有什
 


