Aman
Aman

Reputation: 602

How can I play a sound when a user presses a button in a MessageBox?

I'm using this code to ask a user for either yes or no, and I would like it to play a sound when the user selects no. But my code plays a sound if the user selects yes or no.

DialogResult dialogResult = MessageBox.Show("Buscar Informações do CEP Online?", "CEP Não Encontrado", MessageBoxButtons.YesNo);
if (dialogResult == DialogResult.Yes)
{
    //do something
   // Process.Start("http://www.buscacep.correios.com.br/servicos/dnec/index.do");
    Process.Start(
        "http://www.buscacep.correios.com.br/servicos/dnec/consultaLogradouroAction.do?Metodo=listaLogradouro&CEP=" +
        maskedTextBoxCep.Text + "&TipoConsulta=cep");
}
else if (dialogResult == DialogResult.No)
{
    //do something else
    SystemSounds.Exclamation.Play();
}

Upvotes: 2

Views: 304

Answers (1)

Johnny
Johnny

Reputation: 56

In some computers I have a code with Process.Start that will make a exclamation noise before running the process, I'm using the same program in 5 different machines and only 1 will beep, the machine that beeps has the same OS as 2 other machines, I still don't know why, try to change your sound to a different one to see if the sound you are hearing is not from the Process.Start "Bug"

Upvotes: 1

Related Questions