基本信息
源码名称:winform 家庭影集 图片循环播放效果 附源码下载
源码大小:0.94M
文件格式:.zip
开发语言:C#
更新时间:2013-04-30
   友情提示:(无需注册或充值,赞助后即可获取资源下载链接)

     嘿,亲!知识可是无价之宝呢,但咱这精心整理的资料也耗费了不少心血呀。小小地破费一下,绝对物超所值哦!如有下载和支付问题,请联系我们QQ(微信同号):813200300

本次赞助数额为: 2 元 
   源码介绍

读取某个目录下的所有图片,并听过 picturebox循环播放


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 TailorFamilyAlbum
{
    public partial class Frm_Main : Form
    {
        string strPath;
        string strInfo="";
        string[] strName=null;
        int Num = 0;
        int Count = 0;
        public Frm_Main()
        {
            InitializeComponent();
            strPath = System.Environment.CurrentDirectory "\\Image";
        }

        public void GetAllFiles(DirectoryInfo dir)
        {
            FileSystemInfo[] fileinfo = dir.GetFileSystemInfos(); 	//初始化一个FileSystemInfo类型的数组
            foreach (FileSystemInfo i in fileinfo) 					//循环遍历fileinfo中的每一个记录
            {
                if (i is DirectoryInfo) 						//当i在类DirectoryInfo中存在时
                {
                    GetAllFiles((DirectoryInfo)i); 				//获取i下的所有文件
                }
                else										//当不存在该i时
                {
                    string str = i.FullName; 				//记录变量i的全名
                    int b = str.LastIndexOf("\\");				//在此示例中获取最后一个匹配项的索引
                    string strType = str.Substring(b   1); 	//保存文件的后缀
                    //当文件格式为“jpg”或者“bmp”时
                    if (strType.Substring(strType.Length - 3) == "jpg" || strType.Substring(strType.Length - 3) == "bmp")
                    {
                        strInfo  = strType   "#";			//为变量strInfo赋值
                    }
                }
            }
        }

        private void Frm_Main_Load(object sender, EventArgs e)
        {
            DirectoryInfo dir = new DirectoryInfo(strPath); 			//实例化一个DirectoryInfo类对象
            GetAllFiles(dir); 								//获取dir下的所有文件
            if (strInfo != "")								//当字符串不为空时
            {
                strName = strInfo.Split('#'); 					//获取文件名
                Num = 0; 								//初始化Num的值
                showPic(Num); 							//显示图片
                Count = strName.Length - 1; 					//记录Array中的元素数
            }
            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);
            }   
        }
    }
}