国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > C# > 正文

C#圖片查看器實現方法

2019-10-29 21:03:40
字體:
來源:轉載
供稿:網友

實現效果:

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文件夾,并放置圖片


注:相關教程知識閱讀請移步到c#教程頻道。
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 塔河县| 花莲县| 天峻县| 呼和浩特市| 四子王旗| 汽车| 昔阳县| 漳浦县| 汉源县| 五莲县| 邹平县| 尤溪县| 中方县| 子洲县| 满城县| 申扎县| 丰镇市| 芮城县| 霍林郭勒市| 西城区| 白水县| 泰和县| 凌海市| 墨脱县| 孙吴县| 兴安县| 大宁县| 始兴县| 治多县| 永宁县| 三亚市| 连平县| 安多县| 延津县| 镇雄县| 保康县| 孝昌县| 石门县| 镇宁| 林西县| 洛扎县|