Como emitir um beep no C#

Iremos aprender como disparar um Beep quando um botão do windows form é clicado

Criamos os métodos para os eventos Click controle button1.

Importamos, também a dll KERNEL32.DLL, usando o atributo DllImport (System.InteropServices.DllImportAttribute).

O código fica assim:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Runtime.InteropServices;
//
namespace ExemploBeep
{
public partial class Form1 : Form
{
[
DllImport(“kernel32.dll”)]
public static extern bool Beep(UInt32 frequency, UInt32 duration);
//
public Form1()
{
InitializeComponent();
}
//
private void button1_Click(object sender, EventArgs e)
{
Beep(1000, 300);
}
//
  private
void button1_MouseEnter(object sender, EventArgs e)
{
  Beep(500, 100);
}
  }
}

Obrigado e por Hoje é só!
Alguma duvida é só deixar um recado ai vlw! :D

Deixe uma resposta