Search code examples
c#keypressnoise

Stop 'Ding' sound when a Key is pressed


I am aware others have asked this, but the answers have not resolved my problem as the previous questions were slightly different to mine.

private void Form1_KeyDown(object sender, KeyEventArgs e)
{    
    if (e.KeyValue == 221)
    {
        if(pixelSize < 200)
            PixelSizeSelect.Value += 5;
        e.Handled = true;
    }
    if (e.KeyValue == 219)
    {
        if(pixelSize > 5)
            PixelSizeSelect.Value -= 5;
        e.Handled = true;
    }

    e.Handled = false;
}

Whenever I press these Keys that Ding noise plays, it is very annoying especially as if these keys are held down to quickly change the value, the noise plays repeatedly.

I have heard that adding e.Handled = true; prevents the noise, however as you can see I have added it and it has done nothing.


Solution

  • Ok, I have solved it, it was happening because while I was pressing the keys a numericUpDown box was selected. It automatically selects itself when the Form is loaded so I had no idea.