Selecting sounds from Windows and playing them

前端 未结 3 1149
说谎
说谎 2021-02-19 16:01

I have a WinForms app. This app has a Preferences section where the user will be able to select which sounds are played when an alert is being displayed.

Is it possible

3条回答
  •  谎友^
    谎友^ (楼主)
    2021-02-19 16:31

    Try this:

        private void Form1_Load(object sender, EventArgs e)
        {
    
            var systemSounds = new[]
                                  {
                                      System.Media.SystemSounds.Asterisk,
                                      System.Media.SystemSounds.Beep,
                                      System.Media.SystemSounds.Exclamation,
                                      System.Media.SystemSounds.Hand,
                                      System.Media.SystemSounds.Question
                                  };
    
            comboBox1.DataSource = systemSounds;
    
            comboBox1.SelectedIndexChanged += new EventHandler(comboBox1_SelectedIndexChanged);
        }
    
        void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
        {
            ((System.Media.SystemSound)comboBox1.SelectedItem).Play();
        }
    

提交回复
热议问题