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

首頁 > 編程 > C# > 正文

C#圖片查看器實現方法

2020-01-24 00:19:30
字體:
來源:轉載
供稿:網友

實現效果:

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

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 宝兴县| 库车县| 亚东县| 洛川县| 栾城县| 兰州市| 神木县| 上栗县| 天水市| 芜湖市| 莲花县| 平定县| 多伦县| 上犹县| 桐庐县| 湖州市| 通道| 勐海县| 湖南省| 德安县| 南投市| 九寨沟县| 峨边| 大城县| 荔浦县| 绥滨县| 慈利县| 巢湖市| 永善县| 延吉市| 遂宁市| 平和县| 庆城县| 青海省| 安多县| 浠水县| 西乡县| 房山区| 陈巴尔虎旗| 沿河| 新疆|