image.png

    1. public partial class Form1 : Form
    2. {
    3. public Form1()
    4. {
    5. InitializeComponent();
    6. }
    7. string musicPath = "等什么君-霜雪千年-_Live片段_.wav";
    8. private void Form1_Load(object sender, EventArgs e)
    9. {
    10. //播放音乐
    11. SoundPlayer sp = new SoundPlayer();
    12. sp.SoundLocation = musicPath;
    13. sp.Play();
    14. //在窗体加载的时候,修改图像的显示方式
    15. pictureBox1.SizeMode = PictureBoxSizeMode.Zoom;
    16. pictureBox2.SizeMode = PictureBoxSizeMode.Zoom;
    17. pictureBox3.SizeMode = PictureBoxSizeMode.Zoom;
    18. pictureBox4.SizeMode = PictureBoxSizeMode.Zoom;
    19. pictureBox5.SizeMode = PictureBoxSizeMode.Zoom;
    20. pictureBox6.SizeMode = PictureBoxSizeMode.Zoom;
    21. //在窗体加载的时候,给每一个PictureBox都赋值一张图片的路径
    22. string pathPicture = @"李湘莲\f28e255b28b6914df1d849f3e94f0a8.jpg";
    23. pictureBox1.Image = Image.FromFile(pathPicture);
    24. pictureBox2.Image = Image.FromFile(pathPicture);
    25. pictureBox3.Image = Image.FromFile(pathPicture);
    26. pictureBox4.Image = Image.FromFile(pathPicture);
    27. pictureBox5.Image = Image.FromFile(pathPicture);
    28. pictureBox6.Image = Image.FromFile(pathPicture);
    29. }
    30. //获得该文件夹的所有文件路径
    31. string[] path = Directory.GetFiles("李湘莲");
    32. Random r = new Random();
    33. private void timer1_Tick(object sender, EventArgs e)
    34. {
    35. //每隔一秒钟换一张图片
    36. pictureBox1.Image = Image.FromFile(path[r.Next(0, path.Length)]);
    37. pictureBox2.Image = Image.FromFile(path[r.Next(0, path.Length)]);
    38. pictureBox3.Image = Image.FromFile(path[r.Next(0, path.Length)]);
    39. pictureBox4.Image = Image.FromFile(path[r.Next(0, path.Length)]);
    40. pictureBox5.Image = Image.FromFile(path[r.Next(0, path.Length)]);
    41. pictureBox6.Image = Image.FromFile(path[r.Next(0, path.Length)]);
    42. }
    43. private void pictureBox3_Click(object sender, EventArgs e)
    44. {
    45. }
    46. private void pictureBox4_Click(object sender, EventArgs e)
    47. {
    48. }
    49. /// <summary>
    50. /// 实现点击暂停音乐,播放音乐
    51. /// </summary>
    52. /// <param name="sender"></param>
    53. /// <param name="e"></param>
    54. private void buttonPlay_Click(object sender, EventArgs e)
    55. {
    56. if (btnPlay.Text == "播放")
    57. {
    58. //播放音乐
    59. SoundPlayer sp = new SoundPlayer();
    60. sp.SoundLocation = musicPath;
    61. sp.Play();
    62. btnPlay.Text = "停止播放";
    63. }
    64. else if (btnPlay.Text == "停止播放")
    65. {
    66. //播放音乐
    67. SoundPlayer sp = new SoundPlayer();
    68. //sp.SoundLocation = musicPath;
    69. sp.Stop();
    70. btnPlay.Text = "播放";
    71. }
    72. }
    73. private void buttonQuit_Click(object sender, EventArgs e)
    74. {
    75. this.Close();
    76. }
    77. }