private void button2_Click(object sender, System.EventArgs e)
{
FolderBrowserDialog
folder=new FolderBrowserDialog();
if(folder.ShowDialog()==DialogResult.OK)
{
string fileName=folder.SelectedPath;
FindImg(new DirectoryInfo(fileName));
}
else
return;
}
PictureBox[] FindImg(DirectoryInfo
info)
{
if(!info.Exists)
{
return null;
}
FileSystemInfo[] files = info.GetFileSystemInfos();
PictureBox[] pc = new PictureBox[files.Length];
int count=0;
try
{
for(int i=0;i<files.Length;i++)
{
FileInfo file=files[i] as FileInfo;
string[] strArr=file.FullName.Split('.');
if(strArr[strArr.Length-1]=="gif")
{
PictureBox pcture=new PictureBox();
pcture.Image=Image.FromFile(file.FullName);
pc[count]=pcture;
count++;
}
}
}
catch(Exception er)
{
this.label1.Text=er.Message;
}
return pc;
}
所有代码!
谢谢!