Hashtable ht = new Hashtable();
string s;
public Form1()
{
InitializeComponent();
s = Environment.CurrentDirectory + "//Image";
}
private void Form1_Load(object sender, EventArgs e)
{
DirectoryInfo dir = new DirectoryInfo(s);
GetAllFiles(dir);
foreach (DictionaryEntry de in ht)
this.comboBox1.Items.Add(de.Key);
}
public void GetAllFiles(DirectoryInfo dir)
{
FileSystemInfo[] fileinfo = dir.GetFileSystemInfos();
foreach (FileSystemInfo fsi in fileinfo)
{
if (fsi is DirectoryInfo)
GetAllFiles((DirectoryInfo)fsi);
else
{
string str = fsi.FullName;
int b = str.LastIndexOf("\\");
string strType = str.Substring(b + 1);
if (strType.Substring(strType.Length - 3) == ".jpg" || strType.Substring(strType.Length - 3) == "bmp")
ht.Add(strType.Substring(0, strType.Length - 4), strType);
}
}
}
public void showPic(string name)
{
this.pictureBox1.ImageLocation = s + "\\" + name;
}
讀取圖片位置,用按鈕顯示出來