练习:WinForm (PictureBox和Timer)
Posted 庚xiao午
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了练习:WinForm (PictureBox和Timer)相关的知识,希望对你有一定的参考价值。
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 PictureBox和Timer练习 { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void Form1_Load(object sender, EventArgs e) { //设置图片显示样式:平铺 pictureBox1.SizeMode = PictureBoxSizeMode.StretchImage; pictureBox2.SizeMode = PictureBoxSizeMode.StretchImage; pictureBox3.SizeMode = PictureBoxSizeMode.StretchImage; pictureBox4.SizeMode = PictureBoxSizeMode.StretchImage; pictureBox5.SizeMode = PictureBoxSizeMode.StretchImage; pictureBox6.SizeMode = PictureBoxSizeMode.StretchImage; //在窗体加载的时候,给每一个PictureBox都赋值一张图片的路径 pictureBox1.Image = Image.FromFile(@"C:\\Users\\Administrator\\Desktop\\新建文件夹\\2.jpg"); pictureBox2.Image = Image.FromFile(@"C:\\Users\\Administrator\\Desktop\\新建文件夹\\2.jpg"); pictureBox3.Image = Image.FromFile(@"C:\\Users\\Administrator\\Desktop\\新建文件夹\\2.jpg"); pictureBox4.Image = Image.FromFile(@"C:\\Users\\Administrator\\Desktop\\新建文件夹\\2.jpg"); pictureBox5.Image = Image.FromFile(@"C:\\Users\\Administrator\\Desktop\\新建文件夹\\2.jpg"); pictureBox6.Image = Image.FromFile(@"C:\\Users\\Administrator\\Desktop\\新建文件夹\\2.jpg"); } string[] path = System.IO.Directory.GetFiles(@"C:\\Users\\Administrator\\Desktop\\新建文件夹"); Random r = new Random(); private void timer1_Tick(object sender, EventArgs e) { //每隔一秒钟换一张图片 pictureBox1.Image = Image.FromFile(path[r.Next(0,path.Length)]); pictureBox2.Image = Image.FromFile(path[r.Next(0, path.Length)]); pictureBox3.Image = Image.FromFile(path[r.Next(0, path.Length)]); pictureBox4.Image = Image.FromFile(path[r.Next(0, path.Length)]); pictureBox5.Image = Image.FromFile(path[r.Next(0, path.Length)]); pictureBox6.Image = Image.FromFile(path[r.Next(0, path.Length)]); } } }
以上是关于练习:WinForm (PictureBox和Timer)的主要内容,如果未能解决你的问题,请参考以下文章