1. Right click on your project name in solution explorer.
2. Point the cursor on Add then choose Existing Item...
3. Now go to the Location of your sound file and select that sound file.
4. Now select your sound file in solution explorer then Right click on it choose Properties and change its Build Action property(Content to Embedded Resource)
5.Build the program or one time Debug the program.
6. Now if you want to play sound file when a particular Form is loaded then use the given code in Form_Load event.
NOTE:-In this code Dreamer.wav is name of sound file.
ASHISH
Add sound file into Resource and access it. in .net (C#)
using System.Reflection;
using System.IO;
using System.Resources;
using System.Media;
using System.Diagnostics;
namespace Yournamespace
{
public partial class Form2 : Form
{
public Form2()
{
InitializeComponent();
}
private void Form2_Load(object sender, EventArgs e)
{
Assembly assembly;
Stream soundStream;
SoundPlayer sp;
assembly = Assembly.GetExecutingAssembly();
sp = new SoundPlayer(assembly.GetManifestResourceStream("Yournamespace.Dreamer.wav"));
sp.Play();
}
}
}
charqus 0 Junior Poster in Training
charqus 0 Junior Poster in Training
ashishkumar008 2 Light Poster
Shlesh 0 Newbie Poster
ddanbe 2,724 Professional Procrastinator Featured Poster
shahbaz aziz 0 Newbie Poster
ddanbe 2,724 Professional Procrastinator Featured Poster
pradeep_8 0 Newbie Poster
pradeep_8 0 Newbie Poster
Sharp_1 0 Newbie Poster
JOSheaIV 119 C# Addict
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.