10.WinFor练习--自动播放图片小程序

namespace _10Picture和Timer小程序
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}

创新互联公司是一家专业提供连云港企业网站建设,专注与成都网站设计、成都做网站、H5技术、小程序制作等业务。10年已为连云港众多企业、政府机构等服务。创新互联专业网络公司优惠进行中。

    private void Form1_Load(object sender, EventArgs e)
    {
        //程序加载时播放音乐
        SoundPlayer sp = new SoundPlayer();
        sp.SoundLocation = @"C:\Users\Administrator.USER-20180925HC\Desktop\1.wav";
        sp.Play();
        //程序运行时加载图片到picBox
        pictureBox1.Image = Image.FromFile(@"C:\Users\Administrator.USER-20180925HC\Desktop\pic\1.jpg");
        pictureBox2.Image = Image.FromFile(@"C:\Users\Administrator.USER-20180925HC\Desktop\pic\2.jpg");
        pictureBox3.Image = Image.FromFile(@"C:\Users\Administrator.USER-20180925HC\Desktop\pic\3.jpg");
        pictureBox4.Image = Image.FromFile(@"C:\Users\Administrator.USER-20180925HC\Desktop\pic\4.jpg");
        pictureBox5.Image = Image.FromFile(@"C:\Users\Administrator.USER-20180925HC\Desktop\pic\5.jpg");
        pictureBox6.Image = Image.FromFile(@"C:\Users\Administrator.USER-20180925HC\Desktop\pic\6.jpg");
        //图片的显示方式
        pictureBox1.SizeMode = PictureBoxSizeMode.StretchImage;
        pictureBox2.SizeMode = PictureBoxSizeMode.StretchImage;
        pictureBox3.SizeMode = PictureBoxSizeMode.StretchImage;
        pictureBox4.SizeMode = PictureBoxSizeMode.StretchImage;
        pictureBox5.SizeMode = PictureBoxSizeMode.StretchImage;
        pictureBox6.SizeMode = PictureBoxSizeMode.StretchImage;

    }
    string[] path = Directory.GetFiles(@"C:\Users\Administrator.USER-20180925HC\Desktop\pic");

    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)]);
    }
}

}


文章标题:10.WinFor练习--自动播放图片小程序
本文链接:http://bzwzjz.com/article/ggjdos.html

其他资讯

Copyright © 2007-2020 广东宝晨空调科技有限公司 All Rights Reserved 粤ICP备2022107769号
友情链接: 成都网站建设公司 手机网站建设 温江网站设计 成都网站制作 成都定制网站建设 成都网站设计 成都网站建设 成都网站建设 成都网站设计 成都网站建设流程 网站建设改版 成都响应式网站建设 专业网站设计 定制网站设计 成都网站建设 企业网站设计 手机网站建设 H5网站制作 成都企业网站建设 营销型网站建设 网站制作 成都网站建设