2

I'm using this to allow cursor progressing to next TextBox on a WinForm:

private void GoToNextControl(object sender, KeyEventArgs e)
{
    if(e.KeyCode == Keys.Enter)
    {
        this.SelectNextControl((Control)sender, true, true, true, true);
    }
}

This works flawlessly if not for a "ding" sound when I press enter. How could I "silence" the ding?

Chris
  • 5,442
  • 17
  • 30
ArtK
  • 1,157
  • 5
  • 17
  • 31
  • http://stackoverflow.com/questions/6290967/stop-the-ding-when-pressing-enter – Mitch Jan 23 '15 at 22:40
  • @Mitch - I've seen that post. I can't use FormAcceptButton. I'm traversing multiple textboxes with subsequent TabIndexes. I'd have to make that button invisible and attach the method to it - it's not too professional... – ArtK Jan 23 '15 at 22:46

2 Answers2

7

Setting SuppressKeyPress to true in the handler should do it:

private void GoToNextControl(object sender, KeyEventArgs e)
{
    if(e.KeyCode == Keys.Enter)
    {
        this.SelectNextControl((Control)sender, true, true, true, true);
        e.SuppressKeyPress = true;
    }
}

Make sure your handler is hooked up to the KeyDown event, as this won't work in KeyUp.

Chris
  • 5,442
  • 17
  • 30
1

"Ding" sound comes from unhandled Form event. On your Form: 1. Add a button, set its Visible property to false 2. Add OnClick event handler to that button. Keep the method empty 3. Set Form's AcceptButton property to the new button. That's it. "Ding" will be gone.