我们专注攀枝花网站设计 攀枝花网站制作 攀枝花网站建设
成都网站建设公司服务热线:400-028-6601

网站建设知识

十年网站开发经验 + 多家企业客户 + 靠谱的建站团队

量身定制 + 运营维护+专业推广+无忧售后,网站问题一站解决

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练习--自动播放图片小程序
链接URL:http://mswzjz.cn/article/ggjdos.html

其他资讯