- Open "Solution Explorer" from menu toolbar ("VIEW") or simply press Ctrl+Alt+L.
- Click on drop-down list of "Properties".
- Then select "Resource.resx" and press enter.
- Now select "Audio" from the combobox list.
- Then click on "Add Resource", choose audio files (.wav) and click "Open".
- Select audio file(s) and change "Persistence" properties to "Embedded in .resx".
b) Now, just write this code to play the audio.
In this code I'm playing audio on form load event.
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Media; // at first you've to import this package to access SoundPlayer
namespace WindowsFormsApplication1
{
public partial class login : Form
{
public login()
{
InitializeComponent();
}
private void login_Load(object sender, EventArgs e)
{
playaudio(); // calling the function
}
private void playaudio() // defining the function
{
SoundPlayer audio = new SoundPlayer(WindowsFormsApplication1.Properties.Resources.Connect); // here WindowsFormsApplication1 is the namespace and Connect is the audio file name
audio.Play();
}
}
}
That's it.
All done, now run the project (press f5) and enjoy your sound.
All the best. :)
All done, now run the project (press f5) and enjoy your sound.
All the best. :)