Beep In The PC Speaker

Beep In The PC Speaker
Generate a beep in the PC speaker using C# and an unmanaged call to the Beep() function that is part of the Windows kernel.
1. using System;
2. using System.Collections.Generic;
3. using System.ComponentModel;
4. using System.Data;
5. using System.Windows.Forms;
6. using System.Runtime.InteropServices;
8. namespace Sample
9. {
10.    public partial class Form1 : Form
11.    {
12.        public Form1()
13.       {
14.            InitializeComponent();
15.        }
17.        [DllImport("kernel32.dll")]
18.        public static extern bool Beep(int BeepFreq, int BeepDuration);
20.        private void button1_Click(object sender, EventArgs e)
21.        {
22.            Beep(500, 100);
23.        }
24.    }
Nathan Pakovskie is an esteemed senior developer and educator in the tech community, best known for his contributions to With a passion for coding and a knack for simplifying complex tech concepts, Nathan has authored several popular tutorials on C# programming, ranging from basic operations to advanced coding techniques. His articles, often characterized by clarity and precision, serve as invaluable resources for both novice and experienced programmers. Beyond his technical expertise, Nathan is an advocate for continuous learning and enjoys exploring emerging technologies in AI and software development. When he’s not coding or writing, Nathan engages in mentoring upcoming developers, emphasizing the importance of both technical skills and creative problem-solving in the ever-evolving world of technology. Specialties: C# Programming, Technical Writing, Software Development, AI Technologies, Educational Outreach

Leave a Reply

Your email address will not be published. Required fields are marked *

Back To Top