C# 轮流展示照片

代码

C#  轮流展示照片
 1 using System;
 2 using System.Collections.Generic;
 3 using System.ComponentModel;
 4 using System.Data;
 5 using System.Drawing;
 6 using System.Linq;
 7 using System.Text;
 8 using System.Threading.Tasks;
 9 using System.Windows.Forms;
10 
11 using System.Threading;
12 
13 namespace picture_0
14 {
15     public partial class Form1 : Form
16     {
17         public Form1()
18         {
19             InitializeComponent();
20         }
21         
22 
23 Thread th;
24         private void Form1_Load(object sender, EventArgs e)
25         {
26              th = new Thread
27                 (
28                     delegate ()
29                     {
30                   
31                         for (int i = 0; i < 100; i++)
32                         {
33 
34                             ChangeImage(Image.FromFile(@"picture\18720223738_6b6c58f282_o.jpg"), 2000);
35                             ChangeImage(Image.FromFile(@"picture\amargosa-river-stars.jpg"), 2000);
36  
37                         }
38                     }
39                 );
40             th.IsBackground = true;
41             th.Start();
42 
43         }
44         
45 
46      private void Form1_FormClosed(object sender, FormClosedEventArgs e)
47         {
48             th.Abort();//结束线程
49         }
50         
51 
52         private void ChangeImage(Image img, int millisecondsTimeOut)
53         {
54             this.Invoke(new Action(() =>
55             {
56                 pictureBox1.Image = img;
57             })
58                 );
59             Thread.Sleep(millisecondsTimeOut);
60 
61         }
62 
63     }
64 }
代码

 

  

C# 轮流展示照片

上一篇:C#的反射(一)


下一篇:抛弃VMware吧,使用Win10自带的Hyper-V创建虚拟机