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

发布时间:2020-06-10 22:00:09 作者:初禾
来源:网络 阅读:212

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

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

}

推荐阅读:
  1. 5.WinFor练习--小闹钟程序
  2. 小程序如何实现图片移动缩放

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

picture和timer fo --

上一篇:TX Text Control文字处理教程(6)通过代码编辑和格式化文本

下一篇:PHP成长记(三) —— SSO单点登录/登出

相关阅读

您好,登录后才能下订单哦!

密码登录
登录注册
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》