⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 form1.cs

📁 C#程序开发范例宝典 图书光盘附带源码 第五章
💻 CS
字号:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.IO;
namespace Ex05_14
{
    public partial class Form1 : Form
    {
        string strPath;
        string strInfo="";
        string[] strName=null;
        int Num = 0;
        int Count = 0;
        public Form1()
        {
            InitializeComponent();
            strPath = System.Environment.CurrentDirectory+"\\Image";
        }

        public void GetAllFiles(DirectoryInfo dir)
        {
           
            FileSystemInfo[] fileinfo = dir.GetFileSystemInfos();
            foreach (FileSystemInfo i in fileinfo)
            {
                if (i is DirectoryInfo)
                {
                    GetAllFiles((DirectoryInfo)i);
                }
                else
                {
                    string str = i.FullName;
                    int b = str.LastIndexOf("\\");
                    string strType = str.Substring(b + 1);
                    if (strType.Substring(strType.Length - 3) == "jpg" || strType.Substring(strType.Length - 3) == "bmp")
                    {
                        strInfo += strType+ "#";
                    }
                }
            }
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            DirectoryInfo dir = new DirectoryInfo(strPath);
            GetAllFiles(dir);
            if (strInfo != "")
            {
                strName = strInfo.Split('#');
                Num = 0;
                showPic(Num);
                Count = strName.Length-1;
               
            }
            else
            {
                MessageBox.Show("影集里没有照片");
            }
        }

        private void showPic(int X)
        {
            this.pictureBox1.ImageLocation = strPath + "\\" + strName[X];
        }

        private void button2_Click(object sender, EventArgs e)
        {
            Num += 1;
            if (Count >Num)
            {
                showPic(Num);
            }
            else
            {
                Num = 0;
                showPic(Num);
            }
        }

        private void button1_Click(object sender, EventArgs e)
        {
            Num -= 1;
            if (Num>=0)
            {
                showPic(Num);
            }
            else
            {
                Num = Count-1;
                showPic(Num);
            }   
        }
    }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -