a) OK、最初に音声ファイル (.wav) をプロジェクト リソースに追加します。
- メニュー ツールバー ("VIEW") から "Solution Explorer" を開くか、単に Ctrl+Alt+L を押します。
- 「プロパティ」のドロップダウンリストをクリックします。
- 次に、「Resource.resx」を選択し、Enter キーを押します。

- コンボボックスのリストから「オーディオ」を選択します。

- 次に、[リソースの追加] をクリックし、オーディオ ファイル (.wav) を選択して [開く] をクリックします。

- オーディオ ファイルを選択し、「Persistence」プロパティを「Embedded in .resx」に変更します。

b) 次に、このコードを記述してオーディオを再生します。
このコードでは、フォーム ロード イベントでオーディオを再生しています。
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();
}
}
}
そのこと。
すべて完了したら、プロジェクトを実行して (f5 キーを押す)、サウンドを楽しんでください。
さようなら。:)