使用元件:
1.PictureBox
2.Timer
3.using System.IO; //用來做計算檔案數量
話不多說,直接放 Source...
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
int i=1,iCount;
string sCoount;
private void Form1_Load(object sender, EventArgs e)
{
DirectoryInfo di = new DirectoryInfo(@"D:\CSharp_WindowsForm\Lab1\Photos"); //指定目錄
sCoount = di.GetFiles("*.jpg").Length.ToString(); //取得JPG圖檔數量
iCount = Convert.ToInt32(sCoount); //轉成整數
}
private void timer1_Tick(object sender, EventArgs e)
{
if (i <= iCount) //依序取圖檔代號、帶入PictureBox
{
getphoto(Convert.ToString(i));
i++;
}
if (i > iCount) //若筆數已滿、回到第一筆
{
i = 1;
}
}
private void getphoto(string count)
{
pictureBox1.Image = Image.FromFile( "D:\\CSharp_WindowsForm\\Lab1\\Photos\\" + count + ".jpg");
}
}
沒有留言:
張貼留言