C# 图片、播放音乐的测试程序

        //图片
        List<string> pictures = new List<string>();
        int i = 0;
        private void btnOpenFile_Click(object sender, EventArgs e)
        {
            OpenFileDialog openFileDialog = new OpenFileDialog();
            openFileDialog.Title = "请选择图片文件";
            //openFileDialog.InitialDirectory = @"Picture";
            openFileDialog.Multiselect = true;
            openFileDialog.Filter = "图片文件|*.jpeg|所有文件|*.*";

            if (openFileDialog.ShowDialog() == DialogResult.OK)
            {
                string[] path = openFileDialog.FileNames;
                for (int i = 0; i < path.Length; i++)
                {
                    pictures.Add(path[i]);
                }
                pictureBox1.SizeMode = PictureBoxSizeMode.StretchImage;
                pictureBox1.Image = Image.FromFile(pictures[0]);
                pictureBox1.Show();
            }
        }

        private void btnLast_Click(object sender, EventArgs e)
        {
            i--;
            if (i == -1)
            {
                i = pictures.Count - 1;
            }
            pictureBox1.Image = Image.FromFile(pictures[i]);
        }

        private void btnNext_Click(object sender, EventArgs e)
        {
            i++;
            if (i == pictures.Count)
            {
                i = 0;
            }
            pictureBox1.Image = Image.FromFile(pictures[i]);
        }

        //音乐播放器
        List<string> songs = new List<string>();
        private void btnOpenFileSong_Click(object sender, EventArgs e)
        {
            OpenFileDialog openFileDialog = new OpenFileDialog();
            openFileDialog.Title = "请选择音乐文件";
            //openFileDialog.InitialDirectory = @"Song";
            openFileDialog.Multiselect = true;
            openFileDialog.Filter = "音乐文件|*.wav|所有文件|*.*";

            if (openFileDialog.ShowDialog() == DialogResult.OK)
            {
                string[] path = openFileDialog.FileNames;
                for (int i = 0; i < path.Length; i++)
                {
                    listBox1.Items.Add(Path.GetFileName(path[i]));
                    songs.Add(path[i]);
                }
            }
        }

        SoundPlayer soundPlayer = new SoundPlayer();
        private void listBox1_DoubleClick(object sender, EventArgs e)
        {
            soundPlayer.SoundLocation = songs[listBox1.SelectedIndex];
            soundPlayer.Play();
        }

        private void btnLastSong_Click(object sender, EventArgs e)
        {
            int index = listBox1.SelectedIndex;
            index--;
            if (index == -1)
            {
                index = listBox1.Items.Count - 1;
            }
            listBox1.SelectedIndex = index;
            soundPlayer.SoundLocation = songs[index];
            soundPlayer.Play();

        }

        private void btnNextSong_Click(object sender, EventArgs e)
        {
            int index = listBox1.SelectedIndex;
            index++;
            if (index == listBox1.Items.Count)
            {
                index = 0;
            }
            listBox1.SelectedIndex = index;
            soundPlayer.SoundLocation = songs[index];
            soundPlayer.Play();
        }

 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值