■63650 / ) |
Re[2]: c# フォームアプリケーションでの画像の連続表示 |
□投稿者/ poigumi (2回)-(2012/09/21(Fri) 20:37:12)
|
■No63649 (ズッカ さん) に返信
> System.Windows.Forms.Timerを使ってはどうでしょう。
> TimerのIntervalを1000ミリ秒にして、TickイベントでpictureBox1に画像をセットし、カウントを行い、
> 規定回数になったらTimerをStop()すればいいでしょう。
>
> なお、UIスレッドでThread.Sleepを行うのは意味がありません。
> スレッドが停止してしまうのですが、その間スレッドはビジー状態となります。
> UIスレッドでのThread.Sleepの弊害については、ググればたくさんヒットするでしょう。
>
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace 表示
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private string[] s = new string[1000];
private void button1_Click(object sender, EventArgs e)
{
string[] files = System.IO.Directory.GetFiles(@"C:\Users\Ryouhei\Pictures\新しいフォルダー", "*.jpg", System.IO.SearchOption.AllDirectories);
listBox1.Items.AddRange(files);
int _Count = listBox1.Items.Count;
textBox1.Text = _Count.ToString();
for (int i = 0; i < _Count; i++)
{
s[i] = listBox1.Items[i].ToString();
}
for (int i = 0; i < _Count; i++)
{
pictureBox1.Refresh();
pictureBox1.ImageLocation =s[i];
timer1.Start();
}
}
private void timer1_Tick(object sender, EventArgs e)
{
}
}
}
timerののIntervalを1000ミリ秒にしてみたのですが、これだとすぐ最後の画像が表示されてしまいました。自分が勉強不足だとは分かっているのですが、よくわからないのでソースコードを書いていただけないでしょうか?よろしくお願いします。
|
|