|
楼主 |
发表于 2013-9-12 15:38:32
|
显示全部楼层
public partial class Form1 : Form
{
List<Image> imgs =new List<Image>();
private static int i = 0;
public delegate void Mydelegate();
public event Mydelegate Myevent;
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
Bitmap img1 = new Bitmap("E:\\picture\\1.jpg");
Bitmap img2 = new Bitmap("E:\\picture\\2.jpg");
Bitmap img3 = new Bitmap("E:\\picture\\3.jpg");
Bitmap img4 = new Bitmap("E:\\picture\\4.jpg");
imgs.Add(img1);
imgs.Add(img2);
imgs.Add(img3);
imgs.Add(img4);
pictureBox1.Image = imgs;
System.Timers.Timer picture = new System.Timers.Timer();
picture.Elapsed += new ElapsedEventHandler(picture_Elapsed);
picture.Interval = 1000 * 5;
picture.AutoReset = true;
picture.Enabled = true;
}
private void picture_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
{
if (i >= 3)
{
i = 0;
pictureBox1.Image = imgs;
}
else
{
i++;
pictureBox1.Image = imgs;
}
}
private void Mouse_Down(object sender, MouseEventArgs e)
{
i = 0;
if (Myevent != null)
{
Myevent();
}
this.Close();
}
}
public partial class Form2 : Form
{
System.Timers.Timer t = new System.Timers.Timer();
Form1 f = new Form1();
public Form2()
{
InitializeComponent();
f.Myevent +=new Form1.Mydelegate(f_Myevent);
}
private void Form2_Load(object sender, EventArgs e)
{
t.Interval = 1000 * 5;
t.Enabled = true;
t.AutoReset = true;
t.Elapsed += new ElapsedEventHandler(t_Elapsed);
}
private void t_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
{
t.Stop();
f.ShowDialog();
}
private void change(object sender, MouseEventArgs e)
{
t.Stop();
t.Interval = 1000 * 5;
t.Start();
}
void f_Myevent()
{
this.t.Interval = 1000 * 5;
this.t.Start();
}
}
站长 这两段代码form1中的计时器运行几次后时间间隔明显变短了,而且忽快忽慢的。
|
|