In this tutorial, I will teach you how to create a program that will play a beep sound in C#, loops the beep sound, and it will also have a delay to beep.
So, now let's start this tutorial!
1. Let's start with creating a
Windows Form Application for this tutorial by following the following steps in Microsoft Visual Studio 2010: Go to
File, click
New Project, and choose
Windows Application.
2. Add three textboxes labeled as Play Beep Sound, Play Beep Sound 3x, and Play Beep Sound with Delay .
3. Now, have this code below.
To have a beep sound, put this code in button1. This will trigger to play the beep sound once.
private void button1_Click(object sender, EventArgs e)
{
Console.Beep();
}
Now, in button2, we will make the beep sound to beep 3 times. We will just put a for loop and put the beep code inside the loop.
private void button2_Click(object sender, EventArgs e)
{
for (int i = 1; i <= 3; i++)
{
Console.Beep();
}
}
Lastly, for button3, we will create a delay for the beep sound. Thus, this will trigger to pause for a specific seconds to play the beep sound.
We will first import the namespace of Threading. We will use the sleep method for this namespace to have the delay.
using System.Threading;
private void button3_Click(object sender, EventArgs e)
{
for (int i = 1; i <= 3; i++)
{
Console.Beep();
Thread.Sleep(1000);
}
}
And now it's done! Try to click the buttons to hear the output :)
For more inquiries and need programmer for your thesis systems in any kind of programming languages, just contact my number below.
Best Regards,
Engr. Lyndon Bermoy
IT Instructor/System Developer/Android Developer/Freelance Programmer
If you have some queries, feel free to contact the number or e-mail below.
Mobile: 09488225971
Landline: 826-9296
E-mail:
[email protected]
Add and Follow me on Facebook:
https://www.facebook.com/donzzsky
Visit and like my page on Facebook at:
https://www.facebook.com/BermzISware