|
||||||
| C# Programming C# (pronounced C-sharp) is a new object oriented language from Microsoft and is derived from C and C++. It also borrows a lot of concepts from Java too including garbage collection. |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Display Modes |
|
|||
|
How can I add sounds to my program? I want to make a beep like I hear when the computer is first turned on. Anyone know how this is done using .NET language and C#?
|
| Sponsored Links |
|
|
|
|||||
|
Not all computers make that sound.
Those computers there do probably uses different frequencies though. If you just want to make a simple "beep", the standard "beep" of the computer, you can simply output '\a'. It will produce a single "beep." Code:
Console.WriteLine("\a");
<edit> I found this thread, on another forum regarding the same problem. It might be useful for you. Make a Beep - .NET C# </edit>
__________________
CodeCall Blog | CodeCall Wiki | Shareware | Linux Forum C/C++ resources - C/C++ frequently asked questions Python resources - Python frequently asked questions I'm always up for a chat, so feel free to contact me... Last edited by v0id; 06-29-2007 at 09:41 AM. Reason: I found some information... |
|
|||
|
You can also play wav files and other sound formats:
Code:
C#
dialog1.Filter = "Wav Files (*.wav)|*.wav";
C#
using System.Windows.Forms;
namespace WinSound
{
public partial cl*** Form1 : Form
{
private TextBox textBox1;
private Button button1;
public Form1() //constructor
{
InitializeComponent();
}
[System.Runtime.InteropServices.DllImport("winmm.DLL", EntryPoint = "PlaySound", SetLastError = true)]
private static extern bool PlaySound(string szSound, System.IntPtr hMod, PlaySoundFlags flags);
[System.Flags]
public enum PlaySoundFlags : int
{
SND_SYNC = 0x0000,
SND_ASYNC = 0x0001,
SND_NODEFAULT = 0x0002,
SND_LOOP = 0x0008,
SND_NOSTOP = 0x0010,
SND_NOWAIT = 0x00002000,
SND_FILENAME = 0x00020000,
SND_RESOURCE = 0x00040004
}
private void button1_Click (object sender, System.EventArgs e)
{
OpenFileDialog dialog1 = new OpenFileDialog();
dialog1.Title = "Browse to find sound file to play";
dialog1.InitialDirectory = @"c:\";
dialog1.Filter = "Wav Files (*.wav)|*.wav";
dialog1.FilterIndex = 2;
dialog1.RestoreDirectory = true;
if(dialog1.ShowDialog() == DialogResult.OK)
{
textBox1.Text = dialog1.FileName;
PlaySound (dialog1.FileName, new System.IntPtr(), PlaySoundFlags.SND_SYNC);
}
}
}
}
__________________
DirkFirst |
![]() |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | Search this Thread |
| Display Modes | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Windows XP Tricks & Tips!!!!..new ones. | pranky | Tutorials | 9 | 08-23-2008 03:22 PM |
| Computer won't start up. | kool | Computer Hardware | 3 | 08-28-2007 10:18 AM |
| need help with simple C++ TicTacToe game with AI | flupke1 | C and C++ | 11 | 08-14-2007 10:27 AM |
| Sounds and Sound Loop Resources | TVDinner | Website Design | 0 | 03-10-2007 08:20 AM |
| Computer Bug: the first | littlefranciscan | Computer Software/OS | 5 | 02-19-2007 08:58 PM |
| Xav | ........ | 1322.18 |
| MeTh0Dz|Reb0rn | ........ | 1053.7 |
| morefood2001 | ........ | 879.43 |
| John | ........ | 877.37 |
| marwex89 | ........ | 869.98 |
| WingedPanther | ........ | 830.24 |
| Brandon W | ........ | 735.07 |
| chili5 | ........ | 309.39 |
| Steve.L | ........ | 239.84 |
| dcs | ........ | 216.02 |
Goal: 100,000 Posts
Complete: 82%